Deleting a cookie with javascript

Hello I have looked up several example of how to do this but non of them seem to work. I was initially trying in php but it seems to not work because the file I am redirecting from in an include to the original page(well can;t be done as far as I know)

So I have been attempting to delete the cookies with javascript, and then re-direct to the home page if the user's password is invalid.

The following is my code and it produces an infinate re-direct loop.

if ($account['PASS'] != $PASS && isset($PASS)) {
flush();
?>
<script type="text/javascript">
function del_cookie(name)
{
    document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}
del_cookie("ID");
del_cookie("PASS");
window.location = "http://prodynamicsinc.com/"
</script>
<?PHP
die();
}

The desired effect is that the cookie retreived by $PASS (from ($_COOKIE['PASS'])) earlier in the script, should be deleted, and therefore the loop should stop executing, as $PASS would no longer be set.

Thanks in advance for the help!

Upvotes: 1

Views: 121

Answers (1)

Pieter
Pieter

Reputation: 1833

You can clear cookies in PHP without Javascript:

setcookie ("ID", "", time()-3600);
setcookie ("PASS", "", time()-3600); 

Negative time will cause automatic deletion by browser.

Upvotes: 4

Related Questions