Session is a server side variable it works in server, cookies are working in client side. I login to website the session is started, then i clear my browsing history and reload my webpage its logout and redirected to login page.
How it Works?.
How sessions automatically destroyed?

- 297
- 5
- 23
-
3Sessions are (often) based on cookies. – PeeHaa May 07 '16 at 14:35
-
@PeeHaa - How can a session not be based on a cookie? – Ed Heal May 07 '16 at 14:37
-
1@EdHeal by passing the session id in the url – PeeHaa May 07 '16 at 14:39
-
Mr PeeHaa my question is How it Works?. – Sambhu M R May 07 '16 at 14:40
-
The answer explains how it works. The server contains data with an identifier. The client sends the identifier in requests so the server knows what session to use. – PeeHaa May 07 '16 at 14:42
-
`How sessions automatically destroyed?` actually, its not. However since you deleted the cookie with the session id in it theres nothing to connect your requests to the previous, now inaccessible, session data. – AD7six May 07 '16 at 14:43
-
1@PeeHaa - Forgot about that method - even though it is not secure – Ed Heal May 07 '16 at 14:48
3 Answers
The contents of the session are stored at the server. However the session is identified by a session-id
, which is stored at the client and sent with each request.
Usually the session-id is stored in a cookie, but it can also be appended to urls. (That's the PHPSESSID query-parameter you some times see)
So when you clear the browser cache, cookies are deleted(Session_ID is also deleted) and hence session variables can't be accessed.

- 27,209
- 16
- 105
- 126
If your server binds session with cookies for authentication purposes or checks saved cookie in each page load. And if in your browser you have set to delete cookies upon clearing browsing history, then yes it can be done, you can get logged out.
One workout is to try clearing browsing history without clearing cookies set by websites.
As commented, the cookie you delete tells the server who you are. Without it, you need to login in again to get a new identifying cookie.

- 210
- 2
- 9