Difference Between Session and Cookie

Google Advertisements

Prev Tutorial Next Tutorial

Difference Between Session and Cookie in PHP

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.

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.

Difference between cookies and sessions in php
CookiesSessions
Cookies are stored in browser as text file format.Sessions are stored in server side.
It is stored limit amount of data.It is stored unlimited amount of data
It is only allowing 4kb[4096bytes].It is holding the multiple variable in sessions.
It is not holding the multiple variable in cookies.It is holding the multiple variable in sessions.
we can accessing the cookies values in easily. So it is less secure.we cannot accessing the session values in easily.So it is more secure.
setting the cookie time to expire the cookie.using session_destory(), we we will destroyed the sessions.
The setcookie() function must appear BEFORE the <html> tag.The session_start() function must be the very first thing in your document. Before any HTML tags.

Example of Cookie

Example of Cookie

<?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);

?>

Example of Session

Example of Session

<?php
    
session_start();

//session variable
$_SESSION['user'] = 'Hitesh';
 
//destroyed the entire sessions

session_destroy(); 
       
//Destroyed the session 
variable "user".
unset($_SESSION['user']);
?>

Prev Tutorial Next Tutorial

Google Advertisements

We have more than 5 Groups which have 500000+ Members and some Pages have more than 100000+ members. If you want to post your article on our website/FB Group/FB Page please contact on [email protected] or 8076671483

Buy This Ad Space @$50 per Month, Ad Size 600X200 Contact on: [email protected] or 8076671483

Path variable is set for providing path for all Java tools like java, javac, javap, javah, jar, appletviewer which are used in java programming. All these tools are available in bin folders so we set path upto bin folders.

Classpath variable is set for providing a path for predefined Java classes which is used in our application. All classes are available in lib/rt.jar so we set classpath upto lib/rt.jar.

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user.

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects.

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: [email protected] or 8076671483 Try this Keyword C++ Programs