php name _POST name null if name setcookie name _POST name if array_ke

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
<?php
$name = $_POST['name'] ?? null;
if ($name) {
setcookie('name', $_POST['name']);
}
if (array_key_exists('name', $_COOKIE)) {
$counter = isset($_COOKIE['counter']) ? $_COOKIE['counter'] : 0 ;
$counter++;
setcookie('counter', $counter);
echo $counter;
}
?>
<body>
<form method="POST">
<p> Напишите свое имя</p>
<input type="text" name="name">
<input type="submit">
</form>
</body>
</html>