Php Cookie

A cookie is used to store information on the browser:
NOTE: This information can then be used in any part of the website.

How to use a cookie:

Create cookie -> Use the cookie -> End cookie


The code ::

1.) To Create cookie



// Set cookie variables that will last for 24 hours setcookie("my_name", "tobi", time() + (86400 * 30), "/");

?>

2.) Use the cookie


// Echo cookie variables that were set on previous pageecho "My name is " . $_COOKIE["my_name"];
?>


3. To end cookie


// set the expiration date to one hour agosetcookie("user""", time() - 3600);
?>


4. Check if cookies are enabled


if(count($_COOKIE) > 0) {
    echo "Cookies are enabled.";
else {
    echo "Cookies are disabled.";
}
?>


This is it about cookies.

Post a Comment

0 Comments