Session variables don't work!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SabbeRubbish
Forum Newbie
Posts: 10
Joined: Fri May 20, 2005 7:15 am
Location: Belgium

Session variables don't work!

Post by SabbeRubbish »

Hi all,

This aint my first php try, but the following really stuns me:

I have two pages, page1.php and page2.php. I try exchanging variables through SESSION between the two pages.

Code: Select all

<?php
	session_start();
	$_SESSIONї&quote;test&quote;] = &quote;test&quote;;
?>
<html>
<body>
<a href=&quote;page2.php&quote;>Go forward</a>.
</body>
</html>

Code: Select all

<?php
	session_start();
	echo &quote;echoing... &quote;;
	echo $_SESSIONї&quote;test&quote;];
?>
<html>
<body>
Test page...
</body>
</html>
I can't seem to get the "test" string to get in the page:

Code: Select all

echoing... <html>
<body>
Test page...
</body>
</html>
So for some reason, php doesn't want to give me a session, although the session_save_path is set, and most (if not all) values in the php.ini are left default.
Am I missing something out here or is my server misconfigured?

Thanks in advance!
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

try looking at session_register()
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

If its on your home computer then you can turn
register_globals = On
in the php.ini file.
SabbeRubbish
Forum Newbie
Posts: 10
Joined: Fri May 20, 2005 7:15 am
Location: Belgium

Post by SabbeRubbish »

Wayne wrote:try looking at session_register()
Thanks for the idea, but I quote php.net:
If you want your script to work regardless of register_globals, you need to instead use the $_SESSION array as $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where the PHP directive register_globals is disabled.
and:
If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered(), and session_unregister().
from: http://us4.php.net/session_register

My register_globals is off, as it should be...
What could this problem be??
User avatar
wwwapu
Forum Contributor
Posts: 197
Joined: Wed Apr 07, 2004 11:57 am
Location: Turku, Finland

Post by wwwapu »

Problem could be also that cookies are disabled in your browser. PHP prints Notice about undefined index in that case. Default for error_reporting is (if I remember correct) something like E_ALL, ~E_NOTICE

edit Or Firewall program.
SabbeRubbish
Forum Newbie
Posts: 10
Joined: Fri May 20, 2005 7:15 am
Location: Belgium

Post by SabbeRubbish »

wwwapu wrote:Problem could be also that cookies are disabled in your browser. PHP prints Notice about undefined index in that case. Default for error_reporting is (if I remember correct) something like E_ALL, ~E_NOTICE

edit Or Firewall program.
True:

Code: Select all

Notice: Undefined index: test in $DOC_ROOT\php\page2.php on line 4
Thus array $_SESSION does not have a key "test".
Cookies are allowed by Mozilla, and my firewall no longer blocks cookies (ZoneAlarm Integrity Desktop)

But when turning off firewall, all works!
Thank you and sorry for the bother :oops:
User avatar
wwwapu
Forum Contributor
Posts: 197
Joined: Wed Apr 07, 2004 11:57 am
Location: Turku, Finland

Post by wwwapu »

Don't turn off your firewall! Just find the setting that controls cookies and change that.
SabbeRubbish
Forum Newbie
Posts: 10
Joined: Fri May 20, 2005 7:15 am
Location: Belgium

Post by SabbeRubbish »

wwwapu wrote:Don't turn off your firewall! Just find the setting that controls cookies and change that.
LOL Thanks for your concern, of course I'm not turning the firewall off, but there are two settings: Cookie Control (set to Off) and Ad Blocking (set to Medium). Upon setting the Ad Blocking to Off, my session variables DO register...

VERY Strange, must be some kind of ZoneAlarm bug.
Or maybe because the domain for my cookies is not set in the php.ini, anyway, it works now, and I'm not much less protected like this :wink: Thanks!
Post Reply