Sunday, 15 February 2015

session - PHP - session_id does not point the the right session_name -



session - PHP - session_id does not point the the right session_name -

we using server has several services on it. create sure php sessions not mixed, want utilize different cookie each service. created function called sec_session_start define cookie (mysession) service. made sec function called start_my_session connect service cookie.

each time seek utilize start_my_session, gets info within phpsessid instead of mysession. how can prepare that.

the next function called @ 1 place (when user logs system).

function sec_session_start() { $secure = false; $httponly = true; // forces sessions utilize cookies. if (ini_set('session.use_only_cookies', 1) === false) { header("location: ../error.php?err=could not initiate safe session (ini_set)"); exit(); } $cookieparams = session_get_cookie_params(); session_set_cookie_params($cookieparams["lifetime"], $cookieparams["path"], $cookieparams["domain"], $secure, $httponly); session_name('mysession'); session_start(); // start php session. echo session_id(); // utilize @ moment debugging }

the session id returned lastly instruction id corresponding mysession cookie. (i checked in server /tmp folder , within chrome's resources debugger.)

the next function called within everyother secure page 1 time user logged in.

function start_my_session() { echo session_name('mysession').'<br>'; // debug : display phpsessid echo session_name().'<br>'; // debug : display mysession session_start(); // start mysession echo session_id(); // debug : display phpsessid session id }

as mention in comment, session_id still pointing phpsessid instead of mysession.

any advice on doing wrong , how prepare it?

this might not sound logical , you'll think i'm nuts but:

before switch session names session_name(...) (and yes, means it's before session started!)... run session_write_close();

php session cookies

No comments:

Post a Comment