0

Hi guys I'm trying to build a form wich allow me to create cookies, and I want to be able to delete them as well, to do that there is an option at the bottom of the form that send me to my file call see_cookies.php that generate another form with some php to create a loop that will go through al the $_COOKIE array and print every checkbox with the information. Also some submit buttons with allows my to delete all or the ones I choose, but I'm not able to delete them. Could anyone help me please.

this is the code for see_cookies.php:


<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Ver::Cookies</title>
</head>
<body>
        <h1>Cookies en el sevidor</h1>

        <form action="delete_cookies.php" method="post">

            <?php

                foreach ($_COOKIE as $nombre => $contenido) { 
        print <<<pinta
                <input type="checkbox" name="nombre_cookie[]" value="$nombre"/>$nombre($contenido)<br>
pinta;
                 } 
             ?>

            <input type="submit" value="Delete" name="delete">
            <input type="submit" value="Delete_All" name="delete_all"> 


        </form>
</body>
</html>

this is the code for delete_cookie.php

<?php 

function delete_cookie($nombre){
    setcookie($nombre," ",-10);
}

if(isset($_POST["delete_all"])){
    foreach ($_COOKIE as $nombre => $contenido ) {
        delete_cookie($nombre);
    }

}elseif(isset($_POST["delete"])){
    foreach ($_POST["nombre_cookie"] as $key => $contenido) {
        delete_cookie($contenido);
    }
}



 ?>
4

2 回答 2

0

try time less than current time.

setcookie($nombre, "", time()-3600);
于 2013-06-05T11:04:09.873 回答
0

Your second file is named delete_cookie.php when the form action goes to delete_cookies.php. I think that's the problem.

于 2013-06-05T11:06:13.983 回答