Jump to content

SESSION question


amalosoul

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!
Link to comment
https://forums.phpfreaks.com/topic/24966-session-question/
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.
Link to comment
https://forums.phpfreaks.com/topic/24966-session-question/#findComment-113797
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.
Link to comment
https://forums.phpfreaks.com/topic/24966-session-question/#findComment-113798
Share on other sites

Archived

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

×
×
  • 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.