flunn Posted December 19, 2007 Share Posted December 19, 2007 I seem to be missing something very basic about how "sessions" works. If I understand it correctly, I should be able to use it to assign a value to a variable on one page and then access that value on another page. But if I use this code on the first page <?php session_start(); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN"> <html> <head> <title></title> </head> <body> <?php $_SESSIONS['test']= 1; print $_SESSIONS['test']; ?> </body> </html> "1" is returned,but if I try to access the value of $_SESSIONS['test'] on another page with this code: <?php session_start(); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN"> <html> <head> <title></title> </head> <body> <?php if(isset($_SESSIONS['test'])) print $_SESSIONS['test']; else print 'not set'; ?> </body> </html> 'not set' is returned. Any advice would be much appreciated. regards to all from flunn Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 19, 2007 Share Posted December 19, 2007 The proper name is - $_SESSION You are using $_SESSIONS Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 how is 1 returned from <?php $_SESSIONS['test']= 1; print $_SESSIONS['test']; ?> Quote Link to comment Share on other sites More sharing options...
corbin Posted December 19, 2007 Share Posted December 19, 2007 $_SESSIONS['test']= 1; print $_SESSIONS['test']; That's the same thing as doing: $_X['key'] = 'val'; echo $_X['key']; or $x = 1; echo $x; Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 $_SESSIONS['test']= 1; print $_SESSIONS['test']; That's the same thing as doing: $_X['key'] = 'val'; echo $_X['key']; or $x = 1; echo $x; I am not stupid, I was saying how does $_SESSIONS echo anything. He claimed it returned 1 on his first page. You're using $_SESSIONS just to let you know, thats a bad example you just gave me. been coding for 3 years just to let you know. Quote Link to comment Share on other sites More sharing options...
corbin Posted December 19, 2007 Share Posted December 19, 2007 Because when you set a variable, it has a value! Thats identical to doing: x = 1; print x; Just with an array key.... I don't know how to explain it besides saying that lol. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 $_SESSIONS['test']= 1; print $_SESSIONS['test']; That's the same thing as doing: $_X['key'] = 'val'; echo $_X['key']; or $x = 1; echo $x; I am not stupid, I was saying how does $_SESSIONS echo anything. He claimed it returned 1 on his first page. You're using $_SESSIONS just to let you know, thats a bad example you just gave me. been coding for 3 years just to let you know. Quote Link to comment Share on other sites More sharing options...
corbin Posted December 19, 2007 Share Posted December 19, 2007 $_SESSIONS can be created just like $some_array can. If you did: $_some_array['test']= 1; print $_some_array['test']; Would it not put out 1? Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 $_SESSIONS can be created just like $some_array can. If you did: $_some_array['test']= 1; print $_some_array['test']; Would it not put out 1? Yeah it would, but I thought he had the value already set in his $_SESSION, and he was just using it wrong. I know understand what you mean, I was reading his script wrong i guess. edit: Here what i ment $_SESSION['test'] = $_POST['some_field']; // lets say the value was 3 echo $_SESSIONS['test']; // ouputs 3 Thats what i thought he did, and I was getting confused. Quote Link to comment Share on other sites More sharing options...
corbin Posted December 19, 2007 Share Posted December 19, 2007 Oh, yeah.... That would be like magic hehe Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 Oh, yeah.... That would be like magic hehe lol, sorry I misunderstood you. Quote Link to comment Share on other sites More sharing options...
flunn Posted December 19, 2007 Author Share Posted December 19, 2007 Thanks (blush!) to everyone for their replies. with regards from flunn Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.