469,349 Members | 1,532 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,349 developers. It's quick & easy.

Losing Session Variables

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).

Thanks.
Jul 17 '05 #1
4 15210
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.

Example:
<?php session_start(); ?>

<?php
// Other PHP Code Here
?>

Jul 17 '05 #2
"paddy_nyr" <mp****@yahoo.com> wrote in message
news:39*************@individual.net...
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:
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.

$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).


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

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

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.

HTH,
-Josh
Jul 17 '05 #3
"paddy_nyr" <mp****@yahoo.com> wrote in message
news:39*************@individual.net...
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.


Wait, at the top of *one* of your pages? You know you have to have it at
the top of all your pages, right?
Jul 17 '05 #4
Thanks so much for your entry. It worked for me and I've been looking all day for the answer. I use Dreamweaver 8 and it did not have a clue.
Thanks again! Pete Smith


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.

Example:
<?php session_start(); ?>

<?php
// Other PHP Code Here
?>
Mar 21 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by vivek | last post: by
reply views Thread by mbosco51 | last post: by
2 posts views Thread by GFuller | last post: by
2 posts views Thread by M | last post: by
3 posts views Thread by ACaunter | last post: by
2 posts views Thread by Wim Geukens | last post: by
2 posts views Thread by competitions | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.