473,385 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Losing session data on browser close

When a user logs onto my site, I set some session data using php:

....
session_start();
....
$_SESSION['key'] = 'value';
....

From what I understand, this should store the session data (i.e. the
key-value pairs) in a cookie on the user's computer, and it should be
valid until either I destroy the cookie or the user clears their
cookie data. This means that the user should be able to see that data
whenever they log back on the site, right?

And it works when the user leaves the site, and then comes back to it,
as long as they keep their browser open. But when the user closes
their browser, then I seem to lose that data (the cookie seems to
disappear). Why is this? Cookies aren't deleted when the browser is
closed, right?

Thanks,

bgold12
Aug 16 '08 #1
5 4091
bgold12 schrieb am 16.08.2008 11:20:
When a user logs onto my site, I set some session data using php:
...
session_start();
...
$_SESSION['key'] = 'value';
...
From what I understand, this should store the session data (i.e. the
key-value pairs) in a cookie on the user's computer, and it should be
valid until either I destroy the cookie or the user clears their
cookie data. This means that the user should be able to see that data
whenever they log back on the site, right?
Till the Cookie is expired, yes.
And it works when the user leaves the site, and then comes back to it,
as long as they keep their browser open. But when the user closes
their browser, then I seem to lose that data (the cookie seems to
disappear). Why is this? Cookies aren't deleted when the browser is
closed, right?
http://de.php.net/manual/en/function.setcookie.php

Expiration: "If set to 0, or omitted, the cookie will expire at the end
of the session (when the browser closes)."

--
Mit freundlichen Grüßen
Holger Jeromin
Aug 16 '08 #2
On Sat, 16 Aug 2008 02:20:47 -0700 (PDT), bgold12 <bg*****@gmail.com>
wrote:
When a user logs onto my site, I set some session data using php:

And it works when the user leaves the site, and then comes back to it,
as long as they keep their browser open. But when the user closes
their browser, then I seem to lose that data (the cookie seems to
disappear). Why is this? Cookies aren't deleted when the browser is
closed, right?
It depends on the browser configuration. I have Opera and Firefox set
to delete all cookies on exit. So it will work for most users but not
all.
--
Steven
Aug 16 '08 #3
Gazing into my crystal ball I observed bgold12 <bg*****@gmail.com>
writing in news:7f387b18-0f1e-46e7-807d-9fd3ea1da602@
8g2000hse.googlegroups.com:
When a user logs onto my site, I set some session data using php:

...
session_start();
...
$_SESSION['key'] = 'value';
...

From what I understand, this should store the session data (i.e. the
key-value pairs) in a cookie on the user's computer, and it should be
valid until either I destroy the cookie or the user clears their
cookie data. This means that the user should be able to see that data
whenever they log back on the site, right?

And it works when the user leaves the site, and then comes back to it,
as long as they keep their browser open. But when the user closes
their browser, then I seem to lose that data (the cookie seems to
disappear). Why is this? Cookies aren't deleted when the browser is
closed, right?

Thanks,

bgold12
Sessions are for the _session_ - unlike a cookie which can be stored on
a user's computer and can be used at a later time (if the user accepts
cookies, and does not delete them on exit).

You can read the values in a cookie and put them into session variables.
For example, place a user name as a cookie, then read that value next
time the user comes in, request a password and store the password as a
session variable. When the user closes the browser, the cookie will
persist, but the password, which was held in a session variable, will be
destroyed.
--
Adrienne Boswell at Home
Arbpen Web Site Design Services
http://www.cavalcade-of-coding.info
Please respond to the group so others can share

Aug 16 '08 #4
Adrienne Boswell wrote:
Gazing into my crystal ball I observed bgold12 <bg*****@gmail.com>
writing in news:7f387b18-0f1e-46e7-807d-9fd3ea1da602@
8g2000hse.googlegroups.com:
>When a user logs onto my site, I set some session data using php:

...
session_start();
...
$_SESSION['key'] = 'value';
...

From what I understand, this should store the session data (i.e. the
key-value pairs) in a cookie on the user's computer, and it should be
valid until either I destroy the cookie or the user clears their
cookie data. This means that the user should be able to see that data
whenever they log back on the site, right?

And it works when the user leaves the site, and then comes back to it,
as long as they keep their browser open. But when the user closes
their browser, then I seem to lose that data (the cookie seems to
disappear). Why is this? Cookies aren't deleted when the browser is
closed, right?

Thanks,

bgold12

Sessions are for the _session_ - unlike a cookie which can be stored on
a user's computer and can be used at a later time (if the user accepts
cookies, and does not delete them on exit).
True, but the session id is stored in the browser cookie. (unless
session.use_only_cookies is disabled and user browser has cookies
disabled then it put in the URL -- not recommended)

The cookie may be persistent with a expiration date which will be
written to the users hard drive upon browser exit. Or a session cookie
in browser memory which is lost upon browser exit. In either case if the
cookie is removed then the the id is lost and the session on the server
will be orphaned. General house keeping will remove the file after a time.
--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Aug 16 '08 #5
..oO(bgold12)
>When a user logs onto my site, I set some session data using php:

...
session_start();
...
$_SESSION['key'] = 'value';
...

From what I understand, this should store the session data (i.e. the
key-value pairs) in a cookie on the user's computer
Only the session ID is stored in the cookie. The actual data is kept on
the server and should never leave it.
>and it should be
valid until either I destroy the cookie or the user clears their
cookie data. This means that the user should be able to see that data
whenever they log back on the site, right?
No.
>And it works when the user leaves the site, and then comes back to it,
as long as they keep their browser open. But when the user closes
their browser, then I seem to lose that data (the cookie seems to
disappear). Why is this? Cookies aren't deleted when the browser is
closed, right?
By default session cookies are deleted when the browser is closed,
because that's when the session ends.

Micha
Aug 18 '08 #6

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

Similar topics

14
by: Darrin J Olson | last post by:
I am trying to end a session for a site without having to completely close the browser to end it. When I access the site and log in it works fine. If I log out and in with a different account...
2
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...
4
by: Stephen | last post by:
I have a .NET (1.1 framework) application that is losing a session variable on only a few PC's. The main page is loading up in a frame in a Portal application. On the Page_Load it stores an...
1
by: Matthew Curiale | last post by:
I have a ddl that is populated in my If Not IsPostBack block in the Page_load event. A repeater is also populated at this time, showing different domains for a website. The ddl contains different...
9
by: Adrian Parker | last post by:
We have a website that works everywhere but on a few PCs on this one site.. Asp.Net 1.1 Server = Windows 2003 Client = XP In the web.config we use - cookieless="false" in the browser settings...
0
by: Frank Bishop | last post by:
Can someone tell me why I'm losing my session variable when using Response.Redirect? When I use the RedirectFromLoginPage method(currently remmed out below), my session variable works fine, but I'm...
0
by: jason.friesen | last post by:
Hi Folks I have a custom CMS built in classic ASP that is losing session variables. To wit, I can create a situation where my 'show all the set SVs' test page shows a different set of SVs on each...
4
by: rgparkins | last post by:
Hello I am running out of time with a problem I have running PHP 5.04 and Apache 2.0 and really need help :(. I have a page that stores a variable in session but each time I reload that page the...
1
by: KidQuin | last post by:
I am having problems with session value between pages. Happening in both firefox and IE7. I go between page by links so I know it's not header changes. I use session_start as the first line on the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.