Jump to content

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


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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.