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 Link to comment https://forums.phpfreaks.com/topic/82377-solved-a-basic-question-about-sessions/ 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 Link to comment https://forums.phpfreaks.com/topic/82377-solved-a-basic-question-about-sessions/#findComment-418782 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']; ?> Link to comment https://forums.phpfreaks.com/topic/82377-solved-a-basic-question-about-sessions/#findComment-418786 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; Link to comment https://forums.phpfreaks.com/topic/82377-solved-a-basic-question-about-sessions/#findComment-418788 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. Link to comment https://forums.phpfreaks.com/topic/82377-solved-a-basic-question-about-sessions/#findComment-418791 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. Link to comment https://forums.phpfreaks.com/topic/82377-solved-a-basic-question-about-sessions/#findComment-418797 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. Link to comment https://forums.phpfreaks.com/topic/82377-solved-a-basic-question-about-sessions/#findComment-418798 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? Link to comment https://forums.phpfreaks.com/topic/82377-solved-a-basic-question-about-sessions/#findComment-418802 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. Link to comment https://forums.phpfreaks.com/topic/82377-solved-a-basic-question-about-sessions/#findComment-418804 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 Link to comment https://forums.phpfreaks.com/topic/82377-solved-a-basic-question-about-sessions/#findComment-418806 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. Link to comment https://forums.phpfreaks.com/topic/82377-solved-a-basic-question-about-sessions/#findComment-418808 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 Link to comment https://forums.phpfreaks.com/topic/82377-solved-a-basic-question-about-sessions/#findComment-418903 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.