
August 16th, 2008, 10:25 AM
| | | 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 | 
August 16th, 2008, 12:45 PM
| | | Re: Losing session data on browser close
bgold12 schrieb am 16.08.2008 11:20: Quote:
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. Quote:
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 | 
August 16th, 2008, 01:05 PM
| | | Re: Losing session data on browser close
On Sat, 16 Aug 2008 02:20:47 -0700 (PDT), bgold12 <bgold12@gmail.com>
wrote: Quote:
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 | 
August 16th, 2008, 04:35 PM
| | | Re: Losing session data on browser close
Gazing into my crystal ball I observed bgold12 <bgold12@gmail.com>
writing in news:7f387b18-0f1e-46e7-807d-9fd3ea1da602@
8g2000hse.googlegroups.com: Quote:
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 | 
August 16th, 2008, 04:55 PM
| | | Re: Losing session data on browser close
Adrienne Boswell wrote: Quote:
Gazing into my crystal ball I observed bgold12 <bgold12@gmail.com>
writing in news:7f387b18-0f1e-46e7-807d-9fd3ea1da602@
8g2000hse.googlegroups.com:
> Quote:
>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 | 
August 18th, 2008, 03:15 AM
| | | Re: Losing session data on browser close
..oO(bgold12) Quote:
>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. Quote:
>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. Quote:
>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 |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over network members.
|