Write a PHP script to store, retrieve and delete cookies on your local machine.
Set Cookies:-
store cookies using PHP script.
Code :-
<?php
setcookie("name", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", time()+3600, "/","", 0);
setcookie("email", "abc@gmail.com", time()+3600, "/","", 0);
setcookie("no", "123", time()+3600, "/", "", 0);
?>
<html>
<head>
<title>Set Cookies with PHP</title>
</head>
<body>
<?php echo "Set Cookies"?>
</body>
</html>
Output :-Retrieve Cookies:-
Retrieve cookies using PHP script.
Code :-
<html>
<head>
<title> Retrieve Cookies with PHP</title>
</head>
<body>
<?php
if(isset($_COOKIE["name"]))
echo $_COOKIE["name"]. "<br />";
else
echo "Sorry... Name Not recognized" . "<br />";
if(isset($_COOKIE["email"]))
echo $_COOKIE["email"]. "<br />";
else
echo "Sorry... Email Not recognized" . "<br />";
if(isset($_COOKIE["no"]))
echo $_COOKIE["no"]. "<br />";
else
echo "Sorry... No. Not recognized" . "<br />";
?>
</body>
</html>
Delete Cookies:-
Delete cookies using PHP script.
Code :-
<?php
setcookie( "name", "", time()- 60, "/","", 0);
setcookie( "email", "", time()- 60, "/","", 0);
setcookie( "no", "", time()- 60, "/","", 0);
?>
<html>
<head>
<title>Deleting Cookies with PHP</title>
</head>
<body>
<?php echo "Deleted Cookies" ?>
</body>
</html>