jeudi 13 août 2015

Destroy cookie button

I think there might be something I don't get about cookies. I'm trying to destroy a cookie when I click on a button but the cookie stays. I know that instructions for cookies must be before html codes, so I created a new php page with no html code, logout.php:

<?php

if (isset($_COOKIE['pseudocookie'])) {
    setcookie('pseudocookie', '', time()-300); 
}

if(session_id() == '') {
    session_start(); 
}

session_destroy();
session_unset();

header('Location: ../index.php'); ?>

And I'm calling the page from index.php with a simple button :

<input type="button" id="ButSignout" value="Sign out" onclick="window.location.href='pages/logout.php'" />

I did some test, the php page is well loaded, if I try to delete the cookie directly from index.php, it works. What am I missing? Thanks in advance.


The cookie was created with:

setcookie('pseudocookie','Pseudo cookie',time()+$expire, null, null, false, true);



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire