<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
</head>
<br>
<br>
<br>
<!-- <pre><?php print_r( $_COOKIE ); ?></pre> -->
<body class="container">
<table class="table table-light">
<thead class="thead-light">
<tr>
<th>نام کوکی</th>
<th>مقدار کوکی</th>
<th>عملیات</th>
</tr>
</thead>
<tbody>
<?php foreach ($_COOKIE as $key=>$val) { ?>
<tr>
<td><?php echo $key ?></td>
<td><?php echo $val ?></td>
<td><a href="/7Learn/15miniPeroject/CreateCookie.php?name=<?php echo $key ?>">پاک کردن</a></td>
</tr>
<?php } ?>
</tbody>
</table>
<form action="" method="post">
<div class="form-group">
<label for="my-input">Text</label>
<input placeholder="نام کوکی را وارد نمایید" class="form-control" type="text" name="nameCookie">
</div>
<div class="form-group">
<label for="my-input">Text</label>
<input placeholder="محتوای کوکی را وارد نمایید" class="form-control" type="text" name="ValueCookie">
</div>
<button name="submit">ثبت کنید </button>
</form>
</body>
</html>
<?php
if (isset($_POST['submit']) && !empty($_POST['ValueCookie'])) {
$name=$_POST['nameCookie'];
$value=$_POST['ValueCookie'];
setcookie($name, $value);
}
if(isset($_GET['name'])){
$name=$_GET['name'];
setcookie($name, '', time() - 3600);
}
?>