Difference bwtween Cookie and a Session.
The main difference between a cookie and a session is that a cookie is stored on your computer, and a session is not. Although cookies have been around for many years and most people do have them enabled, there are some who do not. Cookies can also be removed by the user at any time, so don't use them to store anything too important.
Before you can store any information in session variables, you must first start up the session using the session_start() function.
The session_start() code must be in the header and you can not send anything to the browser before it.
<?php session_start(); ?>
When you start a session a unique session id (PHPSESSID) for each visitor/user is created. You can access the session id using the PHP predefined constant PHPSESSID.
Storing information in a session
To store information is a session variable, you must use the predefined session variable $_SESSION.
$_SESSION["username"] = "vijay";
$_SESSION["email"] = "email@example.com";