TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
How to Get and Set Cookie in PHP
Bhushan Singh
Mar 25
2016
Code
1.3
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
<?php
$cookie_name =
"user"
;
// name of cookie
$cookie_value =
"John Doe"
;
// set value of cookie
setcookie($cookie_name, $cookie_value, time() + (86400 * 30),
"/"
);
// 86400 = 1 day
?>
<html>
<body>
<?php
if
(!isset($_COOKIE[$cookie_name])) {
echo
"Cookie named '"
. $cookie_name .
"' is not set!"
;
}
else
{
echo
"Cookie '"
. $cookie_name .
"' is set!<br>"
;
echo
"Value is: "
. $_COOKIE[$cookie_name];
}
?>
</body>
</html>
cookie
PHP