|
Posted by ddolgoff on 11/24/07 20:08
Hello to everyone,
I have a problem of managing a session with cookies and
"session_set_save_handler()". I want to use php's built-in session
management mechanism with user-level session storage functions to
store session data on the client in cookies.
The simple implementation that I have works well under PHP 5.2.0 ,
Apache 2.0.54 and WinXP.
When I put it on Linux RHEL3 (Apache/2.0.46 (Red Hat) PHP/5.0.4) I get
the following error:
"Warning: Cannot modify header information - headers already sent
in /......./ct.php on line 37". It seems like a simple error but
setting a cookie with "session_set_save_handler()" becomes kind of
tricky.
Looks like there is something wrong with my "ob_buffering" settings.
I will appreciate if anyone has any ideas or solutions to the problem.
Here is my script:
<?php
function open($save_path, $session_name)
{
return true;
}
function close()
{
return true;
}
function read($id)
{
$sess_name = 'sess_'.$id;
if(isset($_COOKIE[$sess_name]))
{
return base64_decode($_COOKIE[$sess_name]);
}
else
{
return '';
}
}
function write($id, $sess_data)
{
$sess_name = 'sess_'.$id;
if($sess_data) setcookie($sess_name, base64_encode($sess_data), 0,
'/');
ob_end_flush();
return true;
}
function destroy($id)
{
$sess_name = 'sess_'.$id;
setcookie ($sess_name, '', time() - 3600);
return true;
}
function gc($maxlifetime)
{
return true;
}
ob_start();
session_set_save_handler('open', 'close', 'read', 'write', 'destroy',
'gc');
register_shutdown_function('session_write_close');
session_start();
$_SESSION['probe'] = 'session data goes here';
header('Content-Type: text/html; charset=win1252');
print_r($_SESSION);
?>
Thanks to everyone,
Dmitry
Navigation:
[Reply to this message]
|