Cookie Create and Delete and View in same page and other page

 <?php

//When we want to set cookie then cookie should be set before html code as shown below:
$cookie_name = "user";
$cookie_value = "Hello World";

//  To set the cookie, setcookie() function is used
setcookie($cookie_name, $cookie_value, time() + (86400), "/");


?>

<html>
    <body>
        <?php
            if(!isset($_COOKIE[$cookie_name]))
            {
                echo "Cookie is not set";
            }
            else
            {
                echo $_COOKIE[$cookie_name];
            }
        ?>
    </body>
</html>



Below is other File(Page)
<?php
echo "Cookie Value : " . $_COOKIE["user"];

// For delete Cookie as shown below:
setcookie("user", "", time() - (86400 * 30), "/");
?>




Comments

Popular posts from this blog

Ajax Insert Records in Database Tutorial in PHP

SubQuery with EXISTS and NOT EXISTS in PHP

Submitting HTML Form data in JSON File (without MySql Database) in PHP