Sunday, December 9, 2007

What is the difference between session and cookie?

1. The main difference between cookies and sessions is that cookies are stored in the user's browser, and sessions are not.

2.A cookie can keep information in the user's browser until deleted. But Session work instead like a token allowing access and passing information while the user has their browser open.

3.The difference between sessions and cookies is that a session can hold multiple variables, and you don’t have to set cookies for every variable. By default, the session data is stored in a cookie with an expiry date of zero, which means that the session only remains active as long as the browser. When you close the browser, all the stored information is lost. You can modify this behavior by changing the “session.cookie_lifetime” setting in “php.ini” from zero to whatever you want the cookie lifetime to be.


session_start(); //starts or resumes a function
session_destroy(); //ends the session; comment this line and the browser will output the same session ID as before
If you want to remove the registered variables, you need to use the session_unset() function.

No comments: