Connecting Tech Pros Worldwide Forums | Help | Site Map

how to keep a session variable alive across browser closings

laredotornado@zipmail.com
Guest
 
Posts: n/a
#1: Aug 16 '07
Hi,

When a user logs into our site, we create a session variable to denote
the session is active and another to denote who is logged in. Once
the user closes the browser and re-opens it, the session is destroyed
and the variables are gone.

How can I keep the session alive for 24 hours even if the user closes
and re-opens the browser?

I'm using PHP 4.4.4. Thanks, - Dave


Chris Hope
Guest
 
Posts: n/a
#2: Aug 16 '07

re: how to keep a session variable alive across browser closings


laredotornado@zipmail.com wrote:
Quote:
When a user logs into our site, we create a session variable to denote
the session is active and another to denote who is logged in. Once
the user closes the browser and re-opens it, the session is destroyed
and the variables are gone.
>
How can I keep the session alive for 24 hours even if the user closes
and re-opens the browser?
>
I'm using PHP 4.4.4. Thanks, - Dave
You would need to change the cookie that is set to have an expiry 24
hours from now. Session cookies are set to have an expiry of the
current time (or earlier) and are lost when the browser is closed. If
the cookie's expiry is set some time into the future it will persist
even if the browser is closed.

--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
Rik
Guest
 
Posts: n/a
#3: Aug 16 '07

re: how to keep a session variable alive across browser closings


On Thu, 16 Aug 2007 22:59:18 +0200, laredotornado@zipmail.com
<laredotornado@zipmail.comwrote:
Quote:
Hi,
>
When a user logs into our site, we create a session variable to denote
the session is active and another to denote who is logged in. Once
the user closes the browser and re-opens it, the session is destroyed
and the variables are gone.
>
How can I keep the session alive for 24 hours even if the user closes
and re-opens the browser?
<http://nl3.php.net/manual/en/ref.session.php>:
Set:
- session.gc_maxlifetime 86400
- session.cookie_lifetime 86400

A note from the manual:
"Note: If different scripts have different values of
session.gc_maxlifetime but share the same place for storing the session
data then the script with the minimum value will be cleaning the data. In
this case, use this directive together with session.save_path."

.... which is the case for many shared hosts.

--
Rik Wasmus
gosha bine
Guest
 
Posts: n/a
#4: Aug 17 '07

re: how to keep a session variable alive across browser closings


laredotornado@zipmail.com wrote:
Quote:
Hi,
>
When a user logs into our site, we create a session variable to denote
the session is active and another to denote who is logged in. Once
the user closes the browser and re-opens it, the session is destroyed
and the variables are gone.
>
How can I keep the session alive for 24 hours even if the user closes
and re-opens the browser?
>
I'm using PHP 4.4.4. Thanks, - Dave
>
The whole purpose of sessions is to keep short-term data until the
"connection" is closed. If you need persistence, create a normal,
long-term cookie via setcookie() and read it from the $_COOKIES array.

--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
laredotornado@zipmail.com
Guest
 
Posts: n/a
#5: Aug 20 '07

re: how to keep a session variable alive across browser closings


On Aug 16, 4:11 pm, Rik <luiheidsgoe...@hotmail.comwrote:
Quote:
On Thu, 16 Aug 2007 22:59:18 +0200, laredotorn...@zipmail.com
>
<laredotorn...@zipmail.comwrote:
Quote:
Hi,
>
Quote:
When a user logs into our site, we create a session variable to denote
the session is active and another to denote who is logged in. Once
the user closes the browser and re-opens it, the session is destroyed
and the variables are gone.
>
Quote:
How can I keep the session alive for 24 hours even if the user closes
and re-opens the browser?
>
<http://nl3.php.net/manual/en/ref.session.php>:
Set:
- session.gc_maxlifetime 86400
- session.cookie_lifetime 86400
>
A note from the manual:
"Note: If different scripts have different values of
session.gc_maxlifetime but share the same place for storing the session
data then the script with the minimum value will be cleaning the data. In
this case, use this directive together with session.save_path."
>
... which is the case for many shared hosts.
>
--
Rik Wasmus
So would I need to add
Quote:
- session.gc_maxlifetime 86400
- session.cookie_lifetime 86400
on every page beneath the "session_start()" command?

- Dave

Rik
Guest
 
Posts: n/a
#6: Aug 20 '07

re: how to keep a session variable alive across browser closings


On Mon, 20 Aug 2007 22:46:20 +0200, laredotornado@zipmail.com
<laredotornado@zipmail.comwrote:
Quote:
On Aug 16, 4:11 pm, Rik <luiheidsgoe...@hotmail.comwrote:
Quote:
>On Thu, 16 Aug 2007 22:59:18 +0200, laredotorn...@zipmail.com
>>
><laredotorn...@zipmail.comwrote:
Quote:
Hi,
>>
Quote:
When a user logs into our site, we create a session variable to denote
the session is active and another to denote who is logged in. Once
the user closes the browser and re-opens it, the session is destroyed
and the variables are gone.
>>
Quote:
How can I keep the session alive for 24 hours even if the user closes
and re-opens the browser?
>>
><http://nl3.php.net/manual/en/ref.session.php>:
>Set:
> - session.gc_maxlifetime 86400
> - session.cookie_lifetime 86400
>>
>A note from the manual:
>"Note: If different scripts have different values of
>session.gc_maxlifetime but share the same place for storing the session
>data then the script with the minimum value will be cleaning the data.
>In
>this case, use this directive together with session.save_path."
>>
>... which is the case for many shared hosts.
>>
>--
Please don't quote signatures.
Quote:
>
So would I need to add
>
Quote:
> - session.gc_maxlifetime 86400
> - session.cookie_lifetime 86400
>
on every page beneath the "session_start()" command?
No, if this is what you're using you should set it in either:
- php.ini
- httpd.conf (if apache, possibly only for a single virtual host, use
'php_value name_of_setting value_of_setting')
- .htaccess (if apache)
- and only if all possibilities above aren't possible use ini_set()
_before_ session_start() in your scripts.

If you're on a shared server you probably haven't got access to php.ini &
httpd.conf, in which case you really need to create your ow
session.save_path to prevent your longer lived sessions timing being
collected by garbage collectors of shorter lived sessions.

Allthough I agree with gosha bine, use sessions for people that are really
active, possible make a 'keep me logged in' construct with just a cookie
(which possibly revives an 'archived' session).
--
Rik Wasmus
John Murtari
Guest
 
Posts: n/a
#7: Aug 21 '07

re: how to keep a session variable alive across browser closings


Quote:
Quote:
>When a user logs into our site, we create a session variable to
>denote
>the session is active and another to denote who is logged in. Once
>the user closes the browser and re-opens it, the session is destroyed
>and the variables are gone.
>How can I keep the session alive for 24 hours even if the user closes
>and re-opens the browser?
>
The whole purpose of sessions is to keep short-term data until the
"connection" is closed. If you need persistence, create a normal,
long-term cookie via setcookie() and read it from the $_COOKIES array.
>
Yes, pay attention to this comment. I work at a web provider
and 'session' storage is not free. The data is stored in a directory
and depending on php.ini settings data is purged (unless there is an
explicit logout, the server never know if it is okay to destroy the
session data). Right now that data is being periodically purged
for you at the server end -- even if you increased the 'lifetime', it
is quite possible your provider will purge the session data due to
inactivity - or - you could have a LOT of session data pile up.

If you just want to remember their login name for when they
come back, just a simple cookie might be best.

Best regards!
--
John
__________________________________________________ _________________
John Murtari Software Workshop Inc.
jmurtari@following domain 315.635-1968(x-211) "TheBook.Com" (TM)
http://thebook.com/
Closed Thread