I have a login page which upon successfully validating email and password against the values of the database creates 3 session variables. The problem is that I’m unable to access these 3 session variables from other scripts even though session_start() is called before trying to access the variables from other scripts. On the login page too session__start() is called in the beginning and I’m able to print these 3 session variables on the same login page upon page refresh too.
My php version is 7.4 and the server is apache. I’m on a windows machine.
2
Answers
Found the solution. I noticed that the login page was opened through localhost in the url while the script2 trying to access the session variables was being opened up through 127.0.0.1. Sessions in php are unique to the domain, so localhost and 127.0.0.1 are treated differently.
This is your code but simplified. Run, enter your email and password, click "login". Refresh the page a few times with F5