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.
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_uvalue, 3600, "/");
//expire cookies setcookie($cookie_uname,"",-3600); ?>
|
Example: <?php session_start(); //session variable $_SESSION['testvaraible'] = 'Codings';
variable "testvaraible". unset($_SESSION['testvaraible']); ?> |
Related Posts:
1. 413 “Request Entity Too Large” error with uploading a file
2. Difference between cookies and sessions in php
3. How to create a .webp image in PHP
4. How to expire PHP session after a period of time
5. How to resolved when Logged out sessions get restored by back button
6. why javascript contains property is not working in chrome browser
7. what are the differences between json and jsonp
8. Abstract Class in Php
1. 413 “Request Entity Too Large” error with uploading a file
2. Difference between cookies and sessions in php
3. How to create a .webp image in PHP
4. How to expire PHP session after a period of time
5. How to resolved when Logged out sessions get restored by back button
6. why javascript contains property is not working in chrome browser
7. what are the differences between json and jsonp
8. Abstract Class in Php