Session timeout

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tdsrogers
Forum Newbie
Posts: 11
Joined: Sat Mar 06, 2010 12:44 pm

Session timeout

Post 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
incubi
Forum Contributor
Posts: 119
Joined: Mon Dec 07, 2009 1:47 pm

Re: Session timeout

Post 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
Post Reply