Jump to content

Recommended Posts

Wondered the function that i would use to compare time, i am going to get the time at session start and then compare it with the time at the end of the session, if that is over 30 minutes then the session is ended. What you recon? breaking the time down into year/month/day/minute/hours/seconds and save the infomation into the database... what you guys recon?

This is really old, but it worked when I made it.

 

This you do when you set the session.

		$temp = getdate();
		$_SESSION['timestampmday'] = $temp['mday'];
		$_SESSION['timestamphours'] = $temp['hours'];
		$_SESSION['timestampminutes'] = $temp['minutes'];

		$_SESSION['user'] = $_POST['user'];

 

 

Then check it for timing out with this:

function testTime()
{
$newtime = getdate();
if ($newtime['mday'] != $_SESSION['timestampmday'])
	session_destroy();
if ($_SESSION['timestampminutes'] <= 49)
{
	if ($newtime['hours'] != $_SESSION['timestamphours'])
		session_destroy();
	if ($newtime['minutes'] >= ($_SESSION['timestampminutes']+10))
		session_destroy();
}
else
{
	$newtest = (60-$_SESSION['timestampminutes']);
	if ($newtime['minutes'] <= 10)
	{
		if (($newtime['minutes']+$newtest) >= 10)
			session_destroy();
	}
	else
	{
		if ($newtime['hours'] != $_SESSION['timestamphours'])
			session_destroy();
	}
}
}

 

I think if they keep the browser open for one day and start clicking again at the exact same hour it started it will still let them in.

I agree...

 

A simple timestamp will do.

 

<?php

  function check_session($current) {

    session_start();

    $sess_limit = 1200;
    $sess_start = $_SESSION['sess_start'];

    $session_time = ($current - $sess_start);

      if($session_time > $sess_limit) {
        session_destroy();

        header("location: index.php?action=logout");
        exit;
      }

        else
        {
          //Update the your session...or whatever.
         }

  }

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.