Difference Between Session and Cookie

Advertisements

Session in PHP Connect PHP Code with DataBase

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

Session in PHP Connect PHP Code with DataBase

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements