|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75350 set session_name and use session_regenerate_id,session will lose.
Submitted: 2017-10-10 10:16 UTC Modified: 2017-10-10 11:03 UTC
From: freeng at qq dot com Assigned: cmb (profile)
Status: Not a bug Package: Session related
PHP Version: 7.1.10 OS: windows10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
46 - 14 = ?
Subscribe to this entry?

 [2017-10-10 10:16 UTC] freeng at qq dot com
From manual page:
1.set the different value by session_name() to the php.ini
(normal when the same value)
2.set some session value. new request,the value will lose

Test script:
$_SESSION['a'] = 1;
//current request $_SESSION=['a'=>1];
//new request $_SESSION=[];


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-10-10 10:18 UTC] freeng at qq dot com
1.set the different value by session_name() to the php.ini
(normal when the same value)
2.execute session_regenerate_id();
3.set some session value. new request,the value will lose
 [2017-10-10 10:25 UTC]
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2017-10-10 10:25 UTC]
Apparently, you didn't call session_start()
 [2017-10-10 10:58 UTC] freeng at qq dot com
session auto start.

the new name(cd) session tmp file,content is 
the ab session tmp file ,content is 

right value.

so i looked
Thus, you need to call session_name() for every request (and before session_start() or session_register() are called). 

so i turn auto start off,
and run

it's ok.
 [2017-10-10 11:03 UTC]
Exactly. You can change the session name in code but it's only temporary - PHP won't remember it for next time. You have to change it every time, and it has to be done before PHP tries to access the session data.
 [2018-05-30 10:24 UTC] tony at marston-home dot demon dot co dot uk
Your problem is that you have more than one call to session_start(), and the second call fails just like the documentation says it should.

If you have already used session_start() then you cannot call it again with calling session_write_close() beforehand. Your code should be as follows: 

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Mar 22 17:03:43 2023 UTC