Jump to content

Archived

This topic is now archived and is closed to further replies.

amalosoul

SESSION question

Recommended Posts

Lets assume that I have a variable $_SESSION[a]. In one page I assign it a value for example 2 and in another page another value lets say 10. When two people visit these two pages at the same time what value does $_SESSION[a] have? Will it have different values depending on the user, or will $_SESSION[a] point to the same address, thus having the same value?

Thank you in anticipation!

Share this post


Link to post
Share on other sites
I think you missed the whole thing about sessions.
Each user has, stored on [b]his[/b] computer, a Session-ID (SID). Everytime you call session_start(), the server checks if the user has a SID yet, or not. If he doesn't have, he sets him his own diffrent SID. But if he does, he pulls out the information stored on the server according to his SID. So if for an example page1.php sets $_SESSION['a']=1, page2.php sets $_SESSION['a']=2 and page3.php prints the value of $_SESSION['a']. If user number 1 goes to page1.php and then to page3.php, the output will be "1". If user number 2 goes to page2.php and then to page3.php, the output will be "2", and it doesnt matter what pages user1 visited, because each user has it's unique SID, and that's why they have variables with diffrent values.

Read more about sessions:
http://www.tizag.com/phpT/phpsessions.php
http://codewalkers.com/tutorials/32/1.html
and more on google- http://www.google.com/search?hl=en&q=php+sessions+tutorial


Orio.

Share this post


Link to post
Share on other sites
Each user will have an individual session. Your scenario is a bit misleading though, as if you assign the $_SESSION['a'] = 2 on page one, and then $_SESSION['a'] = 10 on page 2, then $_SESSION['a'] will STILL = 2 on page one, and $_SESSION['a'] will STILL = 10 on page 2 irrespective of the user involved. You see what I mean?

If however, one user is on page 1 and the other is on page 2, then $_SESSION['a'] will be equal to the relevant value set on the respective page for each individual user.

Share this post


Link to post
Share on other sites
Ok, thank you very much! I got it now:)... The values are different for different users!
Better late than never:)!

Thank you very much for your pacience!

Share this post


Link to post
Share on other sites

×

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.