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

Advertisements

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

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

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

Download Projects

Google Advertisements


Buy Websites 9999595223

Buy Fresh and Payment Receive Media.net Account with Website. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements