Now I know that with the code below I am compairing 2 strings but I understood that while working with time that was the case, this is apparent that it is probably not the case so anyone give me any pointers on how to do this?
Thanks in advance for aby help.
I set the session on login with the following:
Code: Select all
<?php
$session_timeout = date("y-m-d H:i:s", time()) + 3600; // + 1 hour
// Set the cookie
session_name("OPL_login");
session_start();
session_register("crypted_password");
session_register("session_timeout");
$HTTP_SESSION_VARS["crypted_password"]=$crypted_password;
$HTTP_SESSION_VARS["session_timeout"]=$session_timeout;
$timed_out = "Your session has timed out, ";
?>Code: Select all
<?php
$session_name = $_REQUEST[session_name()]; // Get session name
$session_time = $_SESSION[session_timeout]; // Get session name
$time_now = date("y-m-d H:i:s", time());
if (isset($session_name)) { // Session was set
if ($time_now > $session_timeout) { // Session is within the time allowed (1 hour)
$session_error = $timed_out."you will need to log in again";
header ("location: userlogin.php?session_error=$session_error");
}else{
echo "User has logged in within the hour";
}
}else{ // Session has not been set
$session_error = "You need to log in to gain access to the page you are attemping to load";
header ("location: userlogin.php?session_error=$session_error");
}
?>