Page 1 of 1

Session timeout

Posted: Wed Apr 13, 2011 11:18 am
by tdsrogers
Hi everyone, been a while since my last thread. :D

Ive got a session named 'username' that is working fine but I just need a simple script to force a session timeout.

The session script is as follows:

Code: Select all

session_start();
if( ! $_SESSION['username'])
{
header("location:index.php");
}
?>

<?php

	$uname = $_SESSION['username'];

Does anyone have a simple session timeout script?

Thanks to anyone in advance.

tdsrogers

Re: Session timeout

Posted: Wed Apr 13, 2011 5:08 pm
by incubi
$now = time();
$timeout = 30 // minutes
ini_set("session.gc_maxlifetime", $timeout * 60);
ini_set("session.cookie_lifetime", $now + $timeout * 60);
ini_set("session.cache_expire", $timeout);
session_name("mysession");
session_start();

Found at
http://www.phpbuilder.com/board/showthr ... t=10244189