Hi, I have a problem with custom Session class.
ob_start();
$session = new SessionClass();
echo "Test output";
In SessionClass
function __destruct() {
session_regenerate_id(true);
session_write_close();
}
but,
Warning: session_regenerate_id() [function.session-regenerate-id]: Cannot regenerate session id - headers already sent
Only
echo "Test output";
before
session_regenerate_id(true)
As warning said you, check that there is some output before the use session_regenerate_id(true) function.
Constructor:
session_set_save_handler(array(__CLASS__, '_open'),
array(__CLASS__, '_close'),
array(__CLASS__, '_read'),
array(__CLASS__, '_write'),
array(__CLASS__, '_destroy'),
array(__CLASS__, '_gc'));
session_name($sessionName);
session_start();
But test file must response json data: echo “Test output”;
Oh!
Before __destruct:
ob_flush();
ob_start();
session_start();
echo "Test output";
ob_flush(); // Warning: session_regenerate_id() [function.session-regenerate-id]: Cannot regenerate session id - headers already sent
session_regenerate_id(true);
session_write_close();
Solutions: Don’t send any output to the browser before calling the destruct method, or use output buffering.
Whats happening in the constructor?