Tutorial :$_SESSION variables not transferring from page to page


If I write the following code:

session_start();  $_SESSION['user_id']='daniel';  

the variable stays fine as long as I'm on the page on which it was created, and the second I try to call $_SESSION['user_id'] from another page, I don't get a response. Can anyone tell me what mistake I'm making?


You should be using session_start() on every page you want to use sessions on.


As long as:

  • You are doing session_start() on the other page. Note: you don't make this call once. You do it on every page that wants to access the session information;
  • The other page can see your cookie from this site (ie sufficiently similar domain); and
  • The other page is running on the same server.

then it can see it. Construct a simple test case and verify this and then work out why what you're doing is different.


You must have session_start() on every page


Ensure that the PHPSESSID cookie is actually being set, and that no headers / content have been sent before you call session_start()

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »