Hi,

How can store $_SESSION['id']="myId"; for 5 hours? I tried cache thing but, when i closed IE it expired. When i echo $_SESSION, it doesn't return any value.

Thanks

session_cache_expire(150);
session_start();
$_SESSION['id']="myId";

session is only for the time the user has your site opened

if you need expiry time after you close the browser, use cookies as architact stated

Hi,

I need to store customer's shopping basket. I think therefore, i need to use cookie for it as you said because, if i use session then, everything will disappaer after exiting from web site.

Did i understand right?

Hi,

How can store $_SESSION['id']="myId"; for 5 hours? I tried cache thing but, when i closed IE it expired. When i echo $_SESSION, it doesn't return any value.

Thanks

session_cache_expire(150);
session_start();
$_SESSION['id']="myId";

Just a note:

The session_cache_expire() function does not set the lifetime of the session. It only sets the lifetime of cached web pages which have a session.

From http://www.php.net/session_cache_expire

After recieving a "bogus" mark on a bug report i've tried to find out the differences between cache_expire and what was causing a session delete after 24 minutes.

cache_expire is used for cached session pages and has nothing to do with the session data

The garbage collector controls the session data and destroys sessions which are older then 1440 seconds (24 minutes) by default.

So to keep a session alive longer then 24 minutes (for example when a visitor tries to POST a huge message that took him 1 hour to type), you must modify the session.gc_maxlifetime thru ini_set()

Somehow i couldn't find anything in the PHP documentation regarding this and due to that me (and i think many others) got the wrong ideas regarding PHP sessions.
A few examples to fix session timeout are already posted below but in my opinion they all missed session.gc_maxlifetime

This article has been dead for over six months. Start a new discussion instead.