PDA

View Full Version : php sessions vars expiry all same time



leonidassavvides
08-20-2008, 04:01 PM
php sessions vars expiry all same time, or depends when each get setuped and each may expiry differ time than one other session var ?

Nile
08-20-2008, 04:14 PM
PHP Sessions all delete at the same time:


session_start(); // essential
$_SESSION['date'] = time(); //find out date with mktime()
$_SESSION['day'] = date('l'); //date, for example "Sunday"

These will both end at the same time. Now, perhaps we want one to end before the session is closed, we will use unset(), unset() unsets a variable.


session_start(); // essential
$_SESSION['date'] = time(); //find out date with mktime()
$_SESSION['day'] = date('l'); //date, for example "Sunday"
if($_SESSION['day'] == "Wednesday") { //if the day equals wednesday
unset($_SESSION['day']); //unset it
}
if(isset($_SESSION['day'])){ //if the say session exists
echo "Today isn't Wednesday";
}
else { //if it doesn't
echo "Today is Wednesday";
}

This is just an example of a session ending earlier then another.