By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,871 Members | 2,418 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,871 IT Pros & Developers. It's quick & easy.

Why are session variables not working for me??

P: n/a
Hi,

I am trying to register session variables in the following way:

$_SESSION['myname'] = 'Burnsy';

When i set them and then output the following on the same script:

echo $_SESSION['myname']

... it works, but when I navigate to a different page from the one that
sets the variables it doesnt remember them and I get an error message:

Notice: Undefined index: myname in C:\webserver\Apache2\htdocs\admin
\includes\include.AuthProcess.php on line 20

I have DEFINETELY remembered to use session_start() at the very start
of my scripts. I am setting the variables inside a class but Im
echo'ing then from the running script .. should this matter? Do I need
to do anything in php.ini or something like that? Is it maybe using
cookies for sessions? If so, I dont know a great deal about this ..
please briefly explian what I should do. Any help would be much
appreciated. Thanks

Burnsy
Dec 19 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Wed, 19 Dec 2007 12:06:14 +0100, bizt <bi******@yahoo.co.ukwrote:
Hi,

I am trying to register session variables in the following way:

$_SESSION['myname'] = 'Burnsy';

When i set them and then output the following on the same script:

echo $_SESSION['myname']

.. it works, but when I navigate to a different page from the one that
sets the variables it doesnt remember them and I get an error message:

Notice: Undefined index: myname in C:\webserver\Apache2\htdocs\admin
\includes\include.AuthProcess.php on line 20

I have DEFINETELY remembered to use session_start() at the very start
of my scripts.
Of all scripts using a sessions offcourse, not just the one setting the
variables.
I am setting the variables inside a class but Im
echo'ing then from the running script .. should this matter?
Nope, $_SESSION is a superglobal, so that should work
Do I need
to do anything in php.ini or something like that? Is it maybe using
cookies for sessions?
By default, yes. With a transparent session id it can also be propagated
as a POST or GET value (see the manual:
<http://www.php.net/manual/en/ref.session.php>
If so, I dont know a great deal about this ..
please briefly explian what I should do. Any help would be much
appreciated.
First check wether or not your session is actually carrier over. echo
session_id(), and check wether it remains the same. If it isn't, your
browser probably ignores the cookie. If it is, something is overwriting
your session. If you use the default session handler (files), check where
these files are stored (session.save_path), and wether the session files
are created/filled.

In rare cases (concurrent requests/long processing time) it can be
advisable to do all your session work early on and call
session_write_close(). Normally there is no need though.
--
Rik Wasmus
Dec 19 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.