Jump to content


Photo

SESSION question


  • Please log in to reply
3 replies to this topic

#1 amalosoul

amalosoul
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 24 October 2006 - 07:30 PM

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!

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 24 October 2006 - 07:42 PM

I think you missed the whole thing about sessions.
Each user has, stored on his 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...phpsessions.php
http://codewalkers.c...rials/32/1.html
and more on google- http://www.google.co...ssions tutorial


Orio.
Think you're smarty?

(Gone until 20 to November)

#3 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 24 October 2006 - 07:44 PM

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.

#4 amalosoul

amalosoul
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 24 October 2006 - 07:54 PM

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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users