Sessions in php

Sessions used to store information on server.
Session variables are used to store the details in server.
Can be store unlimited amount of data.

Once a connection made with server, all data like, input field information, etc will be stored in server. Once user logged out, or browser closed otherwise connection lost, session  will be unset.

So this is the main difference between session and cookies:

if user logged out, or browser closed session variable will be destroyed.
Cookies will be there until its expiry time, if expiry time is not specifies, then cookies will be destroyed once the browser closed.

In php we can use the session variable like:


To destroy the session variable use unset($_SESSION[‘name’]);

To destroy all the variables use, session_destroy();


More about cookies: Cookies

Posted in Php