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:
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