Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session Time Remaining?

Status
Not open for further replies.

cleansedbb

Technical User
Feb 11, 2002
95
US
Hello all, I am trying to get the following to work. What it's supossed to do is read in the $SESS_time and give me
the var that should be $time1 but everytime I do it changes
on refresh. i.e. $SESS_time = time();

how do you lock time(); to not refresh on reload?
the following works if I hard code in $time1.

Thanks for the replys

<?
$expire = &quot;10800&quot;; // expire in 3 hours
$time = time(); // time in UTC format
$time1 = '1055990009'; // time of session start $newtime = ($time1 + $expire); // time of expiration
$expiring = ($newtime - $time); // count down to expire

while ($done != 'yes')
{
$hours = ($expiring/(60*60)); // determine hours from seconds
$M = explode('.', $hours); // take remainder to create minutes
$M[1] = &quot;.$M[1]&quot;; // add decimal to allow for multiplication
$min = (($M[1])*(60)); // create minutes
$S = explode('.',$min); // same as above for seconds
$S[1] = &quot;.$S[1]&quot;; // add decimal to allow for multiplication
$sec = (($S[1])*(60)); // create seconds
$done = 'yes';
}
$A = explode('.', $hours); // get first digit w/o .90000
$B = explode('.', $min); // get first digit w/o .90000
$C = explode('.', $sec); // get first digit w/o .90000

$thistime = sprintf(&quot;%02d:%02d:%02d&quot;, $A[0], $B[0], $C[0]); // set time format 00:00:00

echo &quot;Time Remaining in Session: &quot;;
echo $thistime;

?>
 
o.k here is a small idea

sesion_start()
if (isset($_SESSION['time'])==false)
{
//session is empty
($_SESSION['time'])=time();
}

echo $_SESSION['time'];

this must give the time when the page was loaded first...

in the next page where u use this time
$_SESSION['time']=&quot;&quot;;

Known is handfull, Unknown is worldfull
 
tried it and it didnt work?
have another suggestion?
 
the same thing is happening?

Known is handfull, Unknown is worldfull
 
sesion_start()
if (isset($_SESSION['time'])==false)
{
//session is empty
($_SESSION['time'])=time();
}


I added this to both pages

login and test

on login it sets it but on test its getting set again?

 
Got it fixed. thanks for your help!

this is what I ended up using:

<?
session_start();
if (! (isset($timeisset)) )
{
//session is empty
$_SESSION['thisismytime']=date(&quot;U&quot;);
$_SESSION['timeisset'] = 'yes';
}

require('/MySQLHandler.class.php');
require('/SessionHandler.class.php');
$sql = new MySQLHandler();
$sql->Init();
$SessionHandler = new SessionHandler($sql);
if (!$SessionHandler->isLoggedIn($PHPSESSID)) {
header(&quot;Location: login.php&quot;);
}

$ip = getenv(&quot;REMOTE_ADDR&quot;);
$mytime = time();
$exp = ($_SESSION['thisismytime'] + &quot;10800&quot;);
$expiring = ($exp - $mytime);

while ($done != 'yes')
{
$hours = ($expiring/(60*60));
$M = explode('.', $hours);
$M[1] = &quot;.$M[1]&quot;;
$min = (($M[1])*(60));
$S = explode('.', $min);
$S[1] = &quot;.$S[1]&quot;;
$sec = (($S[1])*(60));
$done = 'yes';
}
$A = explode('.', $hours);
$B = explode('.', $min);
$C = explode('.', $sec);

$thistime = sprintf(&quot;%02d:%02d:%02d&quot;, $A[0], $B[0], $C[0]);

require '/header.inc.php';
echo &quot;<br>Session will expire in: &quot; . $thistime . &quot;<br><br>&quot;;
echo &quot;<br>Click <a href=./logout.php>HERE</a> to logout<br><br>&quot;;
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top