hoodedclaw69 Posted September 2, 2007 Share Posted September 2, 2007 hi ppl. Ive been learning sessions for ooh around 12-24 months now and i still cant get the most simple things to work. I have 2 queires, the first one is my priority:- a) The scripts below do not work despite the fact that they have been copied perfectly from tutorials and im sure they should work, but I'm begging, If anyone can see an error or think of a reason why this doesnt work, please, please say so. When i say don't work, page 1 displays the session variable "nike" and also the session ID. When i proceed to page 2, the session ID is the same, but not the session variable 'brandname' - its empty. page 1 <? session_start (); $SESSION["brandname"] = "nike"; echo $SESSION["brandname"]; print session_id(); ?><a href="test2.php?">go to page 2</a> page 2 <? session_start (); print $SESSION["brandname"]; ///this prints nothing at all echo session_id(); //// this prints the same session_ID as page 1 ?> <a href="test1.php">go to p1</a> is there anything wrong here?? What else could be stopping the brandname from being carried?? please if you can 5hikn of anything please say so - im so depserate i cannot explain just how bad i need to figure this out, yet according to all that I've read, it should work. I've tried replacing the ' with " i.e $SESSION['brandname'], but it makes no difference. If the scripts are OK, what else could it be? I tried adding SID to the links, but as the session ID was being carried, it had the 'bugger all' effect i thought it would have. b) I've read in several tutorials that sessions store a cookie server side, so why does this tutorial:- http://php.about.com/od/advancedphp/ss/php_sessions.htm say that "Most sessions set a cookie on your computer to use as a key" (the session_ID). But what i dont understand is that I've also read that cookies are unreliable and this is one of the reasons for using sessions instead. So if sessions use a cookie to store the sessions ID and rely on that sessions ID to identify the user, then why not rely on that cookie to store all the other data? Surely if cookie fail occasionally then they will fail to retrieve the session_id and caused a new session to be created?? Or if I've misunderstood the above and the session is created server side ( which makes sense as i do not get a cookie on my computer from my above scripts, but the sessions ID is carried across the 2 pages ), is there anything else i need to add to the scripts in order to access the variable data? if anyone can help me get the scripts to work, you will always be god in my eyes, you can take one of my daughters as payment and my mother as a housekeeper. Im desperate - literally on the verge of bankruptcy - please if u have anu ideas why the script doesnt work, pls say Quote Link to comment https://forums.phpfreaks.com/topic/67701-very-basic-sessions-help-desperately-needed-verge-of-bankruptcy/ Share on other sites More sharing options...
Fadion Posted September 2, 2007 Share Posted September 2, 2007 it is $_SESSION, not just $SESSION. Quote Link to comment https://forums.phpfreaks.com/topic/67701-very-basic-sessions-help-desperately-needed-verge-of-bankruptcy/#findComment-340105 Share on other sites More sharing options...
Timma Posted September 2, 2007 Share Posted September 2, 2007 So Guilty, which daughter are you going to choose? Quote Link to comment https://forums.phpfreaks.com/topic/67701-very-basic-sessions-help-desperately-needed-verge-of-bankruptcy/#findComment-340106 Share on other sites More sharing options...
ToonMariner Posted September 2, 2007 Share Posted September 2, 2007 problem 1. use $_SESSION not $SESSION. $SESSION = will just set a common old variable (called session) name - while you have a session id you have NOTHING in you session. problem 2. if the user deos not accept cookies then teh onlyway to propagate any kind of state is to pass variables via url or post headers. Depending on your servers settings you may not be able to maintain state across requests if the user won't allow a cookie. when using sessions, the cookie set on the client is just an identifier to a session. ONLY the server can change the values of a session variable whereas any real data stored client side is open to manipulaion - so NEVER store a variable that could be switched to identify someone as admin in a cookie! Quote Link to comment https://forums.phpfreaks.com/topic/67701-very-basic-sessions-help-desperately-needed-verge-of-bankruptcy/#findComment-340108 Share on other sites More sharing options...
Fadion Posted September 2, 2007 Share Posted September 2, 2007 So Guilty, which daughter are you going to choose? U made me fell of my chair. A big LOL. Im passing this as i dont feel alone in this moment LOOL. ToonMariner, u gave a pretty good answer. I can assume u arent satisfied with just one daughter!!! LOOL. jk m8. Quote Link to comment https://forums.phpfreaks.com/topic/67701-very-basic-sessions-help-desperately-needed-verge-of-bankruptcy/#findComment-340112 Share on other sites More sharing options...
ToonMariner Posted September 3, 2007 Share Posted September 3, 2007 I'll have the slutty one if you don't mind! no offence hoodedclaw but I am a busy man - no time for this romancing malarkey! Quote Link to comment https://forums.phpfreaks.com/topic/67701-very-basic-sessions-help-desperately-needed-verge-of-bankruptcy/#findComment-340114 Share on other sites More sharing options...
Timma Posted September 3, 2007 Share Posted September 3, 2007 Now you two are going to be unhappy if those were 3 year olds. Quote Link to comment https://forums.phpfreaks.com/topic/67701-very-basic-sessions-help-desperately-needed-verge-of-bankruptcy/#findComment-340117 Share on other sites More sharing options...
ToonMariner Posted September 3, 2007 Share Posted September 3, 2007 eeeeeeeeeeeeeuuuuuugh don't say that! - I am hoping they are 26-30 and like quote HAVING FUN unquote Quote Link to comment https://forums.phpfreaks.com/topic/67701-very-basic-sessions-help-desperately-needed-verge-of-bankruptcy/#findComment-340126 Share on other sites More sharing options...
Fadion Posted September 3, 2007 Share Posted September 3, 2007 Ok i know i passed this, but changed my mind. If there is one 20 - 25 ill take here. One for me, one for toonmariner as we were the one who helped. Timma, u can always have the mother (as housekeeper normally). Quote Link to comment https://forums.phpfreaks.com/topic/67701-very-basic-sessions-help-desperately-needed-verge-of-bankruptcy/#findComment-340130 Share on other sites More sharing options...
Timma Posted September 3, 2007 Share Posted September 3, 2007 Stuff housekeeping, I shall use her as a pony, a nonsexual pony athankyou. Quote Link to comment https://forums.phpfreaks.com/topic/67701-very-basic-sessions-help-desperately-needed-verge-of-bankruptcy/#findComment-340131 Share on other sites More sharing options...
Fadion Posted September 3, 2007 Share Posted September 3, 2007 Pony?? loooool Quote Link to comment https://forums.phpfreaks.com/topic/67701-very-basic-sessions-help-desperately-needed-verge-of-bankruptcy/#findComment-340135 Share on other sites More sharing options...
Fadion Posted September 3, 2007 Share Posted September 3, 2007 hi ppl. Ive been learning sessions for ooh around 12-24 months now and i still cant get the most simple things to work. I have 2 queires, the first one is my priority:- Being serious. How could be possible to work in php for 12-24 months and make an error as $SESSION?!! Also 12-24 months makes 1 years difference which isnt an approximate time. Quote Link to comment https://forums.phpfreaks.com/topic/67701-very-basic-sessions-help-desperately-needed-verge-of-bankruptcy/#findComment-340136 Share on other sites More sharing options...
hoodedclaw69 Posted September 3, 2007 Author Share Posted September 3, 2007 hi ppl. Ive been learning sessions for ooh around 12-24 months now and i still cant get the most simple things to work. I have 2 queires, the first one is my priority:- Being serious. How could be possible to work in php for 12-24 months and make an error as $SESSION?!! Also 12-24 months makes 1 years difference which isnt an approximate time. ermm..its called SKUNK seriously tho, I've only been doing sessions for the last few months - i got them working once, but didnt know how i did it. i think i must have missed the underscore off back then too - i have been trying this for days now and yes, it was the underscore - im stupid - officially! ps - since the last few hours when i realised that i missed off the underscore, I've gone on to write an almost complete shopping cart, which is good for a noob like me. Well - almost complete, just about to post again with my latest dilemma Quote Link to comment https://forums.phpfreaks.com/topic/67701-very-basic-sessions-help-desperately-needed-verge-of-bankruptcy/#findComment-340272 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.