Click to See Complete Forum and Search --> : how to check if session id has been created


ceanth
07-08-2003, 01:50 PM
i want to create my own session id so i can reference it. i have the following setup:


<?

if (session_id()) {
echo "session has started.";
}
else{
session_start();
$time = time();
$date = $today = date("Ymd");
$id = $time + $date;

session_id($id);

print session_id();
echo "time = $time";
echo "date = $date";
}
?>

This works but when i hit refresh it generates a new session, how can i check if the session id has already been made?

pyro
07-08-2003, 04:36 PM
Try this, perhaps:

<?

session_start();
if (session_id()) {
echo "session has started.";
}
else {
$time = time();
$date = $today = date("Ymd");
$id = $time + $date;

session_id($id);

print session_id();
echo "time = $time";
echo "date = $date";
}
?>

Ash
08-14-2003, 06:13 AM
To test whether the session exists,

if ($PHPSESSID) print "session exists";
else print "session does not exist";

pyro
08-14-2003, 11:17 PM
I wouldn't use global variables... Reference the session like this:

$_SESSION["sessionid"]; #for PHP 4.1.0 and higher

$HTTP_SESSION_VARS["sessionid"] #for lower than PHP 4.1.0