Jump to content

Very Basic Sessions help DESPERATELY needed @ verge of bankruptcy


Recommended Posts

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

 

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!

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.

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).

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.

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 :D

 

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 :D - 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 :D

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.