Re: Overriding session length in existing session?

From: Date: Fri, 04 Mar 2011 00:31:01 +0000
Subject: Re: Overriding session length in existing session?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-311653@lists.php.net to get a copy of this message
At 2:58 PM -0800 3/3/11, Scott Baker wrote:
I have a global header.php file that sets up a bunch of stuff: DB, global variables, and does session_start(). My header.php looks like this: #header.php $cookie_life = (86400 * 7); // Cookies last for seven days session_set_cookie_params($cookie_life,"/",".domain.com",true); session_start(); This is called globally in *all* my scripts. In another script I'd really like to set the session to expire after the browser closes if a uses clicks "public terminal" or something. I thought I could just set the session cookie to expire after the browser closes. Can I override the already started session by doing something like this in my index.php: #index.php include('header.php'); setcookie(session_name(), '', 0 ,"/",".domain.com"); When I do this the session expires IMMEDIATELY. I must be missing something?
Simple answer -- put session_start() at the start of your code -- first line. Cheers, tedd -- ------- http://sperling.com/

« previous php.general (#311653) next »