Why do cookies remain even after the page is redirected, the array of cookies is not displayed? And what does it mean that before sending the setcookie header, the header should not be output?
index.php
<?php error_reporting(-1); header('Content-Type: text/html; charset=utf-8'); ini_set('display_errors', 'On'); if(isset($_POST['login']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) && ($_POST['password'])){ setcookie('name', $_POST['login'], time()+3600*24*30, '/'); setcookie('email', $_POST['email'], time()+3600*24*30, '/'); setcookie('password', $_POST['password'], time()+3600*24*30, '/'); header('Location: index2.php'); } ?> <html> <head> <title>Авторизация</title> </head> <body> <div class="login" style="border: 1px solid; width: 220px; clear: both; overflow: hidden"> <p style="text-align: center;">Вход</p> <form action="" method="post"> <div style="clear: both;"> <span style="float: left">Логин:</span> <input type="text" name="login" style="float: right; width: 150px;"> </div> <div style="clear: both;"> <span style="float: left">Email:</span> <input type="text" name="email" style="float: right; width: 150px;"> </div> <div style="clear: both;"> <span style="float: left">Пароль:</span> <input type="text" name="password" style="float: right; width: 150px;"> </div> <div style="margin-top: 30px; overflow: hidden"> <input type="submit" value="Войти" style="float: right;"> </div> </form> </div> </body> </html> index2.php
<?php error_reporting(-1); header('Content-Type: text/html; char set=utf-8'); ini_set('display_errors', 'On'); if(isset($_GET['exit']) && $_GET['exit'] == 1){ setcookie('name', "", time() - 3600, '/'); header('Location: index.php'); echo '<pre>'; print_r($_COOKIE); echo '</pre>'; exit(); } ?> <html> <head> <title>Личный кабинет</title> </head> <body> <?php echo 'Ваш логин: ' . $_COOKIE['name'] . '<br>'; echo 'Ваш email: ' . $_COOKIE['email'] . '<br>'; echo 'Ваш пароль: ' . $_COOKIE['password'] . '<br>'; ?> <form action="" method="GET"> <input type="hidden" name="exit" value="1"> <a href="index.php?exit=1">Выход</a> </form> </body> </html>