In PHP, visitor information designated to be used across the site can be stored in a session or a cookie. The main difference between cookies and sessions is that information stored in a cookie is stored on the visitor’s browser, and information stored in a session is not—it is stored at the web server.
Cookies
Cookies are stored in browser as a text file format. It is stored limit amount of data.It is only allowing 4kb[4096bytes]. It is not holding the multiple variable in cookies.
Ecample:
<?php setcookie(name, value, expire, path,domain, secure, httponly); $cookie_uame = "user"; $cookie_uvalue= "Hitesh Kumar"; //set cookies for 1 hour time setcookie($cookie_uname, $cookie_uvalue, 3600, "/"); //expire cookies setcookie($cookie_uname,"",-3600); ?>
Sessions
Sessions are stored in server side. It is stored unlimited amount of data.It is holding the multiple variable in sessions. we cannot accessing the cookies values in easily.So it is more secure.
Example:
<?php session_start(); //session variable $_SESSION['user'] = 'Hitesh'; //destroyed the entire sessions session_destroy(); //Destroyed the session variable "user". unset($_SESSION['user']); ?>
Thanks:)
If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.
Leave a Comment