PHP Learning : Cookie - Publik Talk

Breaking

An informative website for every one.

Post Top Ad

Post Top Ad

Wednesday, August 2, 2017

PHP Learning : Cookie

Description:

PHP setcookie() function is used to set cookie with HTTP response. Once cookie is set, you can access it by $_COOKIE superglobal variable.
Firstly cookie is not set. But, if you refresh the page, you will see cookie is set now.

Code:

<?php
 setcookie("user", "file"); //defing name and value only//
?>
<html>
<body>
<?php
if(!isset($_COOKIE["user"])) {
 echo "Sorry, cookie is not found!";
}
else
{
echo "<br/>Cookie Value: " . $_COOKIE["user"]; // returns the cookie value//
}
?>
</body>
</html>


Output:



No comments:

Post a Comment

Post Top Ad