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 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. |
<?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:
<?php session_start(); //session variable $_SESSION['user'] = 'Hitesh'; //destroyed the entire sessions session_destroy(); //Destroyed the session variable "user". unset($_SESSION['user']); ?>
Thực hiện các bước tuần tự theo nội dung Bài học nhé!
Cùng nhau học tập, khám phá các kiến thức nền tảng về Lập trình web, mobile, database nhé.
Nền tảng kiến thức - Hành trang tới tương lai hân hạnh phục vụ Quý khách!
Khám phá, trải nghiệm ngay
Vui lòng đăng nhập để gởi bình luận!
Đăng nhậpChưa có bình luận nào!