Click to See Complete Forum and Search --> : Session age.


DanUK
01-03-2005, 05:40 AM
Hello.
Happy new year!

We use session_start() on our header.php (included on most of our files) and I wondered if there was a way to echo the age of the session. We already echo out the session Id on a particular page, but I saw on another website:


Session Information:
0 minute, 15 second


Thanks.

ShrineDesigns
01-03-2005, 11:19 AM
try this:<?php
session_start();

echo "session expires in: " . session_cache_expire() . " minute{s}";
?>

DanUK
01-03-2005, 06:14 PM
Hello.

Thank you for your reply.

Would that show how long the session has been active? That is what we want to achieve.

By the text you provided it seems it's the expiration...?
*confused*

thanks.

ShrineDesigns
01-03-2005, 10:02 PM
if it does, just subtract the session time from the current time

AdamGundry
01-04-2005, 11:58 AM
Does this help?
session_start();

if (isset($_SESSION['startTime'])){
$age = (time() - $_SESSION['startTime']);
echo 'Session Information: ' . floor($age / 60) . ' minutes, ' . ($age % 60) . ' seconds';
} else {
$_SESSION['startTime'] = time();
echo "Session Information: just started!";
}

Adam