Alex Brest
Alex Brest

Reputation: 105

PHP session not saved for one user

I have a weird problem. I have a web page, that on the main page sets a session variable for each user that visits, and then on the next pages if the session variable is set, some stuff is shown, and some other isn't. The variable i'm setting is just an "1".

 $_SESSION['user_id'] = $user_id;

Everything is simple, everything is working great, but I have this one user, that the server doesn't save the session variable for. Just one guy as far as I know. What can be causing this behaviour? He is using a mac if that matters, but on other macs the website works great.

Thanks.

Upvotes: 1

Views: 153

Answers (2)

Mayukh Roy
Mayukh Roy

Reputation: 1815

HTTP is a stateless protocol. IF session would be only in server side, how could it be able to distinguish between users?

[HTTP is a stateless protocol means: HTTP requests are responded from the server, and it forgets who sent the request, where did that come from.]

This is why cookies are storing the session ids.

In other words, if a user is disabling the cookies, he is not allowing PHP to set the session for himself. This is the reason behind.

Upvotes: 0

Sammitch
Sammitch

Reputation: 32272

When you call session_start() PHP sets a cookie with just the PHPSESSID variable set. This variable is used to identify the client browser with the session data on the server. If your user has disabled cookies, then it is not possible to use sessions without passing PHPSESSID back and forth in every request via GET or POST.

Upvotes: 3

Related Questions