So, I'm still using CodeIgniter and I put this function on my Model for login. So here is my function:
function session_timeout_check()
{
$timeout_max = 1800;//timeout after 30 minutes
$time = $_SERVER['REQUEST_TIME'];
if(isset($_SESSION['LAST_ACTIVITY']))
{
if($time - $_SESSION['LAST_ACTIVITY'] > $timeout_max)
{
return 1;
}
else
{
$_SESSION['LAST_ACTIVITY'] = $_SERVER['REQUEST_TIME'];
return 0;
}
}
else
{
return 1;
}
}
I put that function in the constructor of all controller:
public function __construct()
{
parent::__construct();
$this->load->model(array("M_login"));
session_start();
if($this->M_login->session_timeout_check() == 1)
{
//unsetting session variable, destroying session and redirecting to login page
}
}
inside the if you can put other conditions to check the session.
so that's all folks.
Tidak ada komentar:
Posting Komentar