PHP Cookies and Session Tracking

PHP Cookies and Session Tracking

Cookies:

PHP supports the concept of cookies. Cookie is set using the setcookie function. This function takes in one or more parameters. The first parameter is the cookie name which is mandatory and is given as a string. The second parameter is “true” which is used to define a cookie. The third parameter is the expiration time in seconds. The default value of expiration time is zero which is used to specify that the cookie is destroyed at the end of current session.

 

Session Tracking:

PHP has sessions array which can be used to store information about previous requests of a client during a session. In PHP session ID is created that is the internal value to identify the session. The session array is stored on the server whereas the cookie is stored on the client. The session is handled in PHP using session_start() function which takes no parameters. The first call to session_start() function causes a session ID to be created and subsequent calls to session_start() function retrieves the $_SESSION array which stores any session variables and their values that were registered earlier in the session.

 

For Example: