Follow Me:

Wednesday 1 April 2015

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.

we can accessing the cookies values in easily.So it is less secure.The setcookie() function must appear BEFORE the <html> tag.

Sessions are stored in server side.It is stored unlimit amount of data.It is holding the multiple variable in sessions. we cannot accessing the cookies values in easily.So it is more secure.

Cookies

Sessions

Cookies are stored in browser as
text file format.

Sessions are stored in server side.

It is stored limit amount of data.
It is only allowing 4kb[4096bytes]

It is stored unlimit amount of data.

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.
 The setcookie() function must
 appear BEFORE the <html> tag

we cannot accessing the cookies
values in easily.
So it is more secure.

Destroy Cookies:

 1. if we Closing the browsers at the time
 cookies values destoryed.
 2. setting the cookie time to expire the cookie.

Destroy Sessions :

 1. using unset() session,we will
destroyed the sessions.
 2. using session_destory(), we we will
destroyed the sessions.


Example:

<?php
 
  setcookie(name, value, expire, 
path,domain, secure, httponly);


  $cookie_uame = "codingslover";


  $cookie_uvalue= "website";


  //set cookies for 1 hour time
  setcookie($cookie_uname,
$cookie_uvalue3600, "/");


  //expire cookies
setcookie($cookie_uname,"",-3600);

?>
   


Example:

<?php
    
session_start();

//session variable
$_SESSION['testvaraible'] = 'Codings';
 
//destroyed the entire sessions
session_destroy(); //Destroyed the session 
variable "testvaraible".
unset($_SESSION['testvaraible']);
?>