What is cookie in PHP
In this article I will go to explain about PHP cookie.
PHP Cookies
Cookie is a little piece of client site information. It is used for storing data in the remote browser and thus tracking or identifying returns user.
Create a cookie
You can create a cookie by setcookie().
Syntax of a cookie
setcookie(name, value, expire, path, domain); |
Example of creating a cookie
<html>
<body>
<?php
setcookie("User", "Sharad", time()+2600);
?>
</body>
</html>
|
Example of expiration a cookie
<html>
<body>
<?php
$expire=time()+60*60*24;
setcookie("User", "XYZ", $expire);
?>
</body>
</html>
|
In the above example cookie is expire after 60 sec* 60 min* 24 hours.
Example of retrieve a cookie value
<html>
<body>
<?php
echo $_COOKIE["User"];
print_r($_COOKIE);
?>
</body>
</html>
|
Output of retrieve cookie:
You may also want to read these related articles :here
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here