Fariz Budianto
Fariz Budianto

Reputation: 23

PHP session read false value

I am currently working on a project, where I use 2 php session functions which contain code to display the normal user username and admin. first when I logged in with the admin user session it reads right admin, but when I logged in with a normal user without logging out from admin, the session that was read was the user code but the displayed username is admin user, as an illustration, the following is the script I use on the page normal user:

$id = $_SESSION['user'];

and this is the script I use on the admin page:

$id = $_SESSION['admin'];

As I explained earlier, when I log in and fill in the admin session, the admin session id can be read correctly, but when I log in using the user without logging out from the admin, the session id read on the admin page becomes the user's session. there is something wrong ? Thank you in advance for your help and forgive my poor English

Upvotes: 0

Views: 38

Answers (1)

timgavin
timgavin

Reputation: 5166

I'm posting my comment as an answer so you can mark it solved.

Nothing is wrong, PHP is doing what you're asking it to do, which is display the user session. Logging in as the user basically "logs out" the admin because it creates a new user session.

If you want to test both user and admin at the same time, open a new browser window in privacy mode so you can have two different sessions going at the same time in two different windows.

Upvotes: 1

Related Questions