PHP 8.6.0 Beta 1 is available for testing

Voting

: min(eight, three)?
(Example: nine)

The Note You're Voting On

bachtel at [googles email service]dotcom
9 years ago
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;
}
?>

<< Back to user notes page

AltStyle によって変換されたページ (->オリジナル) /