Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unset cookies php

Tags:

php

cookies

I have this code that setted when login check is fine:

if((isset($_POST["remember_me"]))&&($_POST["remember_me"]==1))
    {
    setcookie('email', $username, time()+3600);
    setcookie('pass', $pass, time()+3600);
    }

Now, when I click on logout link (logout.php) i did this:

<?php session_start();
setcookie("email", '', 1, "");
setcookie("pass", '', 1, "");
$_SESSION["login"] = "";
header("location: aforum/enter_furom.php");
?>

I didn't use destroy session because I don't want to destroy all sessions.... now destroying a session is working fine... but when I try to unset cookies, the browsers (all browsers: explorer, chrome, firefox, mozilla) give me an error saying that the new cookies cant be setted...any help to unset the above cookies ?

like image 723
michael Avatar asked Sep 19 '12 09:09

michael


People also ask

How do you set unset cookies?

setcookie( $cookie_name , $cookie_value , time() + (86400 * 15), "/" ); ?> Deleting Cookie: There is no special dedicated function provided in PHP to delete a cookie. All we have to do is to update the expire-time value of the cookie by setting it to a past time using the setcookie() function.

How do I get rid of cookies?

To unset a cookie, you have to use setcookie() function as well. Just set the expiration time to be someday in the past, and the cookie will be considered unset or deleted, something like this as your second method indicates: setcookie("key","value",time()-3600);

What is Setcookie () function?

The setcookie() function defines a cookie to be sent along with the rest of the HTTP headers. A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too.


1 Answers

setcookie('cookiename', '', time()-3600);
like image 93
xtds Avatar answered Oct 16 '22 16:10

xtds