Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session length 1

Status
Not open for further replies.

TheConeHead

Programmer
Aug 14, 2002
2,106
US
1. How do I tell a session how long to last?


2. Is this right?
Code:
<?php
session_start();

$_SESSION['favcolor'] = 'green';
?>
could I then say:

Code:
<?
if ($_SESSION['favcolor'] == 'green') {


?>

thanks

[conehead]
 
1. If you use session cookies, then the session lasts until the session cookie expires. There are several sessing for that duration. Read about session.cookie_lifetime:

2. Yes, that is right.
You can use the second reference if you are talking about the same script. If it is a distinct script, then you need to also have session_start() at the beginning of the script.
session_start() means that you have access to the session variables. The first time it is called it creates the session ID etc. Every script that needs access to the session data must have the session_start at the very top. If a session with the provided session ID exists session_start() gives access to them.
 
session.cookie_lifetime
session_start()

where do I put this stuff? I get errors with it?

[conehead]
 
thanks man - don't worry, I'll star ya, just don;t want you to be chased away by a star.... one more thing:

what does 2000 represent in this, minutes?

session_set_cookie_params(2000);


[conehead]
 
Just for the record: I'm not after stars. Got plenty.

The manual states:
session.cookie_lifetime specifies the lifetime of the cookie in seconds which is sent to the browser. The value 0 means "until the browser is closed." Defaults to 0.

So, 2000 seconds is 33 minutes and 20 seconds.
 
I know you're not after stars... calm down...

thanks man!

[conehead]
 
Just as an FYI... "until the browser is closed" means different things in Internet Explorer and Firefox.... not sure how they're treated on other browsers.

Let me see if I remember this right...
IE: Until the currently opened browser window is closed
Firefox: Until all browser windows are closed

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top