note 120589 added to function.session-start
| From: | bachtelat | Date: | Fri, 03 Feb 2017 19:54:54 +0000 |
| Subject: | note 120589 added to function.session-start | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-208758@lists.php.net to get a copy of this message | ||
If you are using a custom session handler via session_set_save_handler() then calling
session_start() in PHP 7.1 you might see an error like this:
session_start(): Failed to read session data: user (path: /var/lib/php/session) in ...
As of this writing, it seems to be happening in PHP 7.1, and things look OK in PHP7.0.
It is also hard to track down because if a session already exists for this id (maybe created by an
earlier version of PHP), it will not trigger this issue because the $session_data will not be null.
The fix is simple... you just need to check for 'null' during your read function:
<?php
function read($id)
{
//... pull the data out of the DB, off the disk, memcache, etc
$session_data = getSessionDataFromSomewhere($id);
//check to see if $session_data is null before returning (CRITICAL)
if(is_null($session_data))
{
$session_data = ''; //use empty string instead of null!
}
return $session_data;
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 98.164.64.75
----
Manual Page -- http://php.net/manual/en/function.session-start.php
Edit -- https://master.php.net/note/edit/120589
Del: integrated -- https://master.php.net/note/delete/120589/integrated
Del: useless -- https://master.php.net/note/delete/120589/useless
Del: bad code -- https://master.php.net/note/delete/120589/bad+code
Del: spam -- https://master.php.net/note/delete/120589/spam
Del: non-english -- https://master.php.net/note/delete/120589/non-english
Del: in docs -- https://master.php.net/note/delete/120589/in+docs
Del: other reasons-- https://master.php.net/note/delete/120589
Reject -- https://master.php.net/note/reject/120589
Search -- https://master.php.net/manage/user-notes.php