php - Use of session_id() and session_name -


i new php. managing sessions in code is, start session using session_start(). reading around on web, came across, session_id , session_name.

what use of session_id , session_name. application based, can use session_name , session_id in php.

how write code is:

<?php    session_start();    if(isset($_session['name']))    {        //render page.    }    else    {        session_destroy();        //redirect simple page.    } ?> 

as per code, can use session_id or session_name. style write code, or should choose use session_id , session_name?

thank you.

the session name name of cookie/url param stores session_id. default when create session, special cookie created name phpsessid, session_id, value of cookie later identifies you. can change default session name using session_name, must call session_name, before session_start. hope helps.

edited.

session send cookie, browser, remember php configured use cookies session management.

once cookie has been created , sent browser, can access other cookie, if print_r($_cookie), see php session cookie , value.

the minimum, need call session_start() , start session you, must called, before output data sent browser.

for example, cause error.

 echo "hello"; session_start();  

this because session_start() must called before output sent browser. so, why need session_name(), because allows rename cookie, mentioned default session name phpsessid. renaming session lessens chances of hacker trying find cookie name phpsessid. every php developer knows default session cookie name is, if hacker, cookie think first? not prevention mechanism.

the session_id(), id of session, not used, there convenience used if trying implement own session management php allow this.

in nutshell, session_name or session_id, not necessary start session. if have further questions, can follow me on google page,

https://plus.google.com/113820735365251703271

and happy explain further.


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -