Jump to content

[SOLVED] create new session_id, doesn't work..


Hyaku_

Recommended Posts

Hi!
I'm trying to generate new session_id after each new request, but it looks like it doesn't quite work:
[code]session_start();

echo "Old session ID: ".session_id() . "<BR>";

$oldSessionData = $_SESSION;

session_destroy();
session_start();

$_SESSION = $oldSessionData;

echo "New session ID: ".session_id();
?>[/code]
I got:
[code]Old session ID: 0da4e9ccd19f6d885c29ac94ab2eecac
New session ID: 0da4e9ccd19f6d885c29ac94ab2eecac[/code]
What am I doing wrong? Thanks!
Link to comment
https://forums.phpfreaks.com/topic/32761-solved-create-new-session_id-doesnt-work/
Share on other sites

You are echoing content to the browser within your code while you are trying to modify the session.

Try putting the following line in after your first opening <?php tag and see what you get -
[code]error_reporting(E_ALL);[/code]
Edit: There is also a note in the session_destroy section of the manual that session id must also be unset. This implies that session_destroy only destroys the session data while retaining the id. Your since your code is echoing content to the browser, the second session_start is not doing anything.

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.