user2561316
user2561316

Reputation: 404

why session depends on the browser cookie

Cookies are client side where as sessions are server side but why session not works, if we disable cookies on the browser.

How these both are related in the web-applications.

Upvotes: 0

Views: 885

Answers (2)

Yair Nevet
Yair Nevet

Reputation: 13003

How does your web-application would know if the current request is a new session or not? it most have some indication so it uses the cookies for persisting the session-id.

By the way, you can work in Cookieless mode where the session id is paased through the URL query params.

Upvotes: 0

Wouter de Kort
Wouter de Kort

Reputation: 39898

A server only sees an incoming request for a web page. The server processes this request and sends a response back to the client. There is no persistent connection between the client and the server. Because of this, the server can't tell if this is a returning client or a completely new one.

To enable sessions, you send a value to the client with a unique session id. On each subsequent request the client sends this id back to the server. That way, the server can use the id to load session state for that specific client.

The value is normally send in a cookie. Browsers attach cookies to each request and this way the server knows who's calling. You can also store the session key in the query string of the url but that's not the default.

Upvotes: 2

Related Questions