Running into this error with a application that stores the PHP sessions in a Mysql database. The Error kept coming up and the issue was because of PHP 7.1.
In PHP 7.1 the “read” function for session reading, requires the return to be a string and not null or false.
Here is the previous read function that was being used:
function _read($id){ ///select data $query=mysqli->query('SELECT `data` FROM sessions WHERE `id`="'.$id.'"'); $response=$query->fetch_array(); // Attempt execution - If successful if($read){ return $response['data']; } else { // Return an empty string return ''; } }
Here is the updated function:
function _read($id){ ///select data $query=mysqli->query('SELECT `data` FROM sessions WHERE `id`="'.$id.'" AND `data` IS NOT NULL'); $response=$query->fetch_array(); // Attempt execution - If successful if($read){ return $response['data']; } else { // Return an empty string return ''; } }
The solution was to change the SQL query to see if the data column (where the session data is stored) and if it’s NULL, then return a blank string.
In the initial example the data column gets wiped out when the session is reset (user logs out, etc) and so when the query is run, it will have a response but be empty and that isn’t the same as a blank string. Which is what PHP 7.1 is expecting.