Losing Session Variables

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I place a session_start () within php tags at the top of one of my pages.
Then I get a value and placed it in a php variable called $clientid.

After that, I register the session variable using: session_register
("clientid");  So far o.k. Two pages later, I'm trying to get the value of
that session variable using:

$viewerclientid = $_SESSION['client_id'];  The problem that I'm having is
that while this works in some computers, other users

are having problems. It seems that they lose the value of this session
variable. Both  users, the ones that run this successfully and the ones that
don't seem to be using

IE 6 as a browser on the same version of windows (XP).


Re: Losing Session Variables

I had the same problem when writing my site.  I found that it worked
best by putting <?php session_start(); ?> all by itself on the top of
every page (the very first line before anything else).  After that,
everything seemed to work out much better.

<?php session_start(); ?>

   // Other PHP Code Here

Re: Losing Session Variables

Quoted text here. Click to load it

I would recommend against using session_register - see warning about
register_globals here: http://php.net/session_register

Instead you should simply put things in $_SESSION.  If you don't want to
type out $_SESSION['client_id'] each time you can still do

$client_id = &$_SESSION['client_id'];

Changes to $client_id will be recorded in the session record.

Quoted text here. Click to load it

Are you using redirects anywhere?  You should called session_write_close()
beforehand, as in:

header('Location: http://mysite.com/somepage.php ');

If you do not write out the session before redirecting the browser, there is
a chance that the second page will start up, and read in the session record,
before the first page has finished shutting down and writing the session
record, causing lost session data.  I've experienced this before.


Re: Losing Session Variables

Quoted text here. Click to load it

Wait, at the top of *one* of your pages?  You know you have to have it at
the top of all your pages, right?

Site Timeline