Y
Y
yerdnaandrey2021-04-08 21:52:54
PHP
yerdnaandrey, 2021-04-08 21:52:54

Does deleting cookies not work?

The script for displaying cookies and its subsequent deletion does not work.

<?php if($_COOKIE["auth_reg_error"] != ''): ?>
<div class="input_errors" align="center">
   
    <?php echo $_COOKIE["auth_reg_error"]; 
    unset($_COOKIE["auth_reg_error"]);
    setcookie("auth_reg_error", null, -3600, '/register/');
    ?>

</div>
<?php endif; ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Yuriev, 2021-04-08
@yerdnaandrey

Reading the official setcookie() documentation

setcookie() sets a cookie that will be sent to the client along with other HTTP headers. Like any other header, the cookie must be sent before any other script data is output (this is a protocol limitation). This means that in the script, calls to this function must be placed before the rest of the output , including the output of the and tags , as well as empty lines and whitespace characters.<html><head>

We look at your code
<?php if($_COOKIE["auth_reg_error"] != ''): ?>
<div class="input_errors" align="center">

the output even in your piece of code already starts here, although the other output above is also present <html><head>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question