Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 16th, 2008, 10:25 AM
bgold12
Guest
 
Posts: n/a
Default 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
  #2  
Old August 16th, 2008, 12:45 PM
Holger Jeromin
Guest
 
Posts: n/a
Default 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
  #3  
Old August 16th, 2008, 01:05 PM
Steven Saunderson
Guest
 
Posts: n/a
Default 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
  #4  
Old August 16th, 2008, 04:35 PM
Adrienne Boswell
Guest
 
Posts: n/a
Default 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

  #5  
Old August 16th, 2008, 04:55 PM
Jonathan N. Little
Guest
 
Posts: n/a
Default 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
  #6  
Old August 18th, 2008, 03:15 AM
Michael Fesser
Guest
 
Posts: n/a
Default 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
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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.
Post your question now . . .
It's fast and it's free

Popular Articles