Click to See Complete Forum and Search --> : maintaining state
silent11
10-06-2004, 09:46 AM
could someone show me some code that they use to keep track of a person -- I'm playing around with sessions, however once the browser is clossed the person looses the sessionID. I want to be able to keep that ID even after the browser closes. I guess I could just set a cookie manually, but I was hoping that there would be something I can do with start_session() to make it more sticky.
How do you achieve this?
ShrineDesigns
10-06-2004, 12:04 PM
you can control the "lifetime" of a session with session_cache_expire([int new_cache_expire]), you must call session_cache_expire() before every call to session_start()
silent11
10-06-2004, 12:35 PM
That is what I thought. Why then does this page give me a different sessionID after I
1) open a browser, close it, then
2) open it up again?
<?php
session_cache_expire(60*24*31);
$cache_expire = session_cache_expire();
session_start();
header("Cache-control: private");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>PHP Sessions</title>
</head>
<body>
<?php echo session_id(); ?>
</body>
</html>
ShrineDesigns
10-06-2004, 12:46 PM
because you are not telling it to load a session, example:if(isset($_REQUEST['PHPSESSID']))
{
session_start($_REQUEST['PHPSESSID']);
}
else
{
session_start();
}
silent11
10-07-2004, 12:05 PM
Thanks!