Create Cookies in PHP
While creating the cookie, we have to pass require arguments with it.
The only a name argument is a must but it is better to pass value, expires, and path to avoid any ambiguity.
Syntax : setcookie(name, value, expire, path, domain, secure, HttpOnly);
<?php
$cname="username";
$cval="shivam";
setcookie($cname,$cval,time()+(86400*30),"/");
if(!isset($_COOKIE[$cname]))
{
echo $cname."Not Set";
}
else
{
echo "Set, value is ",$_COOKIE[$cname];
}
?>
Output:Modify Cookies Value in PHP
We use the isset() function to find out if the cookie is set or not.
Modification of the cookie can simply be done again by setting the cookie using the setcookie() function.
The modified cookie can be checked by calling the same cookie with its name to check its modified value.
Delete Cookies in PHP
A deleted cookie can be checked by calling the same cookie with its name to check if it exists or not.
Accessing Cookies Value in PHP
Syntax:
$Value=COOKIE("CookieName"://returns cookie value




Comments
Post a Comment
If you have any query, please let us know