473,574 Members | 2,672 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to keep a session variable alive across browser closings

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

Aug 16 '07 #1
6 5655
la***********@z ipmail.com wrote:
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
Aug 16 '07 #2
Rik
On Thu, 16 Aug 2007 22:59:18 +0200, la***********@z ipmail.com
<la***********@ zipmail.comwrot e:
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_maxl ifetime 86400
- session.cookie_ lifetime 86400

A note from the manual:
"Note: If different scripts have different values of
session.gc_maxl ifetime 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_pa th."

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

--
Rik Wasmus
Aug 16 '07 #3
la***********@z ipmail.com wrote:
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
Aug 17 '07 #4
On Aug 16, 4:11 pm, Rik <luiheidsgoe... @hotmail.comwro te:
On Thu, 16 Aug 2007 22:59:18 +0200, laredotorn...@z ipmail.com

<laredotorn...@ zipmail.comwrot e:
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_maxl ifetime 86400
- session.cookie_ lifetime 86400

A note from the manual:
"Note: If different scripts have different values of
session.gc_maxl ifetime 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_pa th."

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

--
Rik Wasmus
So would I need to add
- session.gc_maxl ifetime 86400
- session.cookie_ lifetime 86400
on every page beneath the "session_start( )" command?

- Dave

Aug 20 '07 #5
Rik
On Mon, 20 Aug 2007 22:46:20 +0200, la***********@z ipmail.com
<la***********@ zipmail.comwrot e:
On Aug 16, 4:11 pm, Rik <luiheidsgoe... @hotmail.comwro te:
>On Thu, 16 Aug 2007 22:59:18 +0200, laredotorn...@z ipmail.com

<laredotorn... @zipmail.comwro te:
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_maxl ifetime 86400
- session.cookie_ lifetime 86400

A note from the manual:
"Note: If different scripts have different values of
session.gc_max lifetime 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_pa th."

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

--
Please don't quote signatures.
>
So would I need to add
> - session.gc_maxl ifetime 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_settin g')
- .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_pa th 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
Aug 20 '07 #6
>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@follow ing domain 315.635-1968(x-211) "TheBook.Co m" (TM)
http://thebook.com/
Aug 21 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1361
by: Robin Edgar Hansen | last post by:
Hi! I'd like to store an object in a session variable and thus keep it 'alive' for the entire session. More precisely I wanted to do this (possibly in Application_OnStart()): import telnetlib cli = telnetlib.Telnet("localhost",9999) Session.SetValue("cli",cli)
9
3630
by: Pack Fan | last post by:
I've noticed that session variables will persist on Mac IE even after all browser windows have been closed. One must quit the program to clear the session variables. This presents a security risk for my session variable based security scheme. Basically, the risk is that a user will login to my site, close the window when done and allow...
3
2906
by: Geoff Winsor | last post by:
Hi, I am experiencing a problem with recalling a session variable which stores whether a person is logged in to a "members only" section of a website. This area of the site has been working flawlessly for a couple of years under Windows 2000 server but now is very inconsistent following a recent upgrade to Windows server 2003. Following a...
2
2412
by: Nate Spillson | last post by:
I have an asp.net web application that uses session variables to store user information (username, security areas, configuration data). When the user logs into the system I store all of this information in a class and then dump it into a session variable. The timeout on the server is set to 2hrs. Every now and then (5min-30min) the web server...
5
4488
by: ton | last post by:
Hi, I keep several variables in a statevalue like: Dim session As SessionState.HttpSessionState = System.Web.HttpContext.Current.Session session("connect") = " FKHFSF " I thought that these variables would be the exclusive use of one connected user/connection. But it looks like that in a multiuser enviroment some variables are shared....
2
3138
by: MisterKen | last post by:
It appears that I'm losing values for session variables when I move from a page like http://www.my_site.com/catalog.aspx to https://www50.ssldomain.com/my_site/login.aspx and vice versa. Are session variables suppose to lose values across different domain names? The www50.ssldomain.com is hosted by the same webhost. It's just how they...
3
1831
by: Mark B | last post by:
I have a aspx form with a combobox drop-down to select 1 country from over 120 countries. On the next web page after that, I also have the same combobox so that the user can make a final confirmation of the data entered and also add some other info. I carry through Session("Country") from the first page. How can I make sure that the...
17
5074
by: Control Freq | last post by:
Hi, Not sure if this is the right NG for this, but, is there a convention for the variable names of a Session variable? I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any guidance appreciated. Regards
8
4183
by: YYZ | last post by:
I'm using asp, not asp.net. I've got some open ended questions that I was really hoping someone in here could answer, or direct me to some resources that will help me answer them on my own. First, the session object. When a new user comes to my site, asp creates a session object, and a session id on that object. That session id is sent...
0
7814
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7736
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8067
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8107
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6464
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5307
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3748
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1352
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1071
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.