<html>
<?php
// Checking if create cookie button is set or not
// and if it is set then creating new cookies
if(isset($_POST["Submit1"])) {
setcookie("name",$_POST["name"], time() + 3600, "/", "", 0);
setcookie("age", $_POST["age"], time() + 3600, "/", "", 0);
setcookie("city", $_POST["city"], time() + 3600, "/", "", 0);
echo "<center><h4>Your Cookies are now Created...</h4></center>";
}
// Checking delete cookie button is set or not
// And if it is set then deleting the cookies
if(isset($_POST["Submit3"])) {
setcookie("name","", time() - 3600, "/", "", 0);
setcookie("age", "", time() - 3600, "/", "", 0);
setcookie("city", "", time() - 3600, "/", "", 0);
echo "<center><h4>Your Cookies are now Deleted...</h4></center>";
}
?>
<head>
<meta charset="utf-8">
<meta name="viewport" content=
"width=device-width, initial-scale=1">
<link rel="stylesheet" href=
"https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<script src=
"https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js">
</script>
</head>
<body style="background:#FADBD8 ">
<center>
<div class="container ">
<h2 style="color:green">GeeksforGeeks</h2>
<strong>Cookie portal</strong><br/><br/>
<form method="POST" action="">
<div class="form-group">Enter Your Name:
<input class="form-control" type="text"
name="name" style="width:500;">
</div>
<div class="form-group">Enter Your Age:
<input class="form-control" type="text"
name="age" style="width:500;"></div>
<div class="form-group">Enter Your City:
<input class="form-control" type="text"
name="city" style="width:500;"></div>
<br/>
<input type="submit" name="Submit1" value="Create Cookie"
style="width:150;margin-left:10px;">
<input type="submit" name="Submit2" value="Retrieve Cookie"
style="width:150;">
<input type="submit" name="Submit3" value="Delete Cookie"
style="width:150;">
</form>
</div>
<?php
// Checking if retrieve cookie button is set or not
// and if it is set and cookies are also stored
// then printing the cookies data otherwise if
// cookies are deleted then printing the message
// that cookies are deleted
if(isset($_POST['Submit2'])) {
if(isset($_COOKIE["name"])) {
// Printing the cookie data
echo "Name = ". $_COOKIE["name"]."<br/>";
echo "Age = ". $_COOKIE["age"]."<br/>";
echo "City = ". $_COOKIE["city"]."<br/>";
}
else
{
echo "<center><h4>Sorry can't retrieve..
Your Cookies are deleted !!</h4></center>";
}
}
?>
</center>
</body>
</html>