Jump to content

how to do session_id('my_session_id') correctly


niranjan81

Recommended Posts

When ther server is configured to use cookies to store session ids, is there any way by which a developer can assign a manual session_id() to the second level / page in the users flow?

Since, unlike session_regenerate_id() the session_id does not set the cookie all by itself. And in the second page, once we do session_start() to reach out to session data we can not repeat session_start.

 

Therefore, in my understanding what we Can Not do is:

 

<?php
session_start();
<----some code here---->
session_id();
session_start();
<---rest of the code--->
?>

 

Since, the second session_start() in the above example is simply ignored.

Nor Can we do it right in the beginning like:

 

<?php
session_id('my_session_id');
session_start();
<---rest of the code--->
?>

 

Since, when we do that the cookie is set to the new session_id which is 'my_session_id' and the old data is then completely Unreachable / Lost

 

The only way I can figure out is:

In the first page do session_id('my_session_id') at the end of the page like

 

<?php
<---rest of the code--->
session_id('my_session_id');
?>

 

and then in the second page do

 

<?php
session_id('my_session_id');
session_start();
<---rest of the code--->
?>

 

Is this the right way of doing it ? Or is there is a better way to accomplish this ?

 

Thanks.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.