[thelist] php session variable needs to persist

Kasimir K evolt at kasimir-k.fi
Wed Nov 9 09:36:02 CST 2005

Juha Suni scribeva in 2005-11-09 14:46:
> Even after reading other peoples posts about this subject, it still seems 
> people make it more complicated than it is.

True, and I'd like to simplify things even a bit more...

> Under normal circumstances leaving your site and coming back a bit later 
> (with the same browser window etc) should not break the session at all.

It helps to bear in mind that HTTP is a stateless protocol. To tie a 
request to a session, the request must carry a session identifier 
(usually in a cookie, but can be deliverd in the URI too, or even in a 
POST request body).

As long as the browser sends this identifier with the request (and the 
session has not timed out on the server), the session is 'alive'.

Usually cookies used for storing a session id have lifetime 0, meaning 
that the browser deletes them when it is closed. So the browser window 
doesn't have to be the same, but the process must be.

And to answer the OP, using PHP's session_start() function and $_SESSION 
superglobal array there shouldn't be any problems. Please have a look at 

And some (untested) code that you might find helpful:
if (!isset($_SESSION['originalReferer'])) {
    $_SESSION['originalReferer'] = $ref


More information about the thelist mailing list