-3

I have problem in my code.

I have tried to search on the right columns some answers that can help me, but i didn't found.

This is my inset code:

<?php
    if(isset($_POST['**'])) {
        $set_time_out = 60;
        setcookie("***", "username", time()+60, "admin");
    }
?>

now, my unset code is:

if(isset($_GET['**']) == '***') {
    unset($_COOKIE['***']);
}

and when i get in to the "get" link, nothing happened.

the cookie still exists.

help, please :)

EDIT

The login code is..

<?php if(isset($_POST['*'])) { $set_time_out = 60; setcookie('***', '**', time()+60, 'admin/'); } ?>

And my "logout" code is :

`

if(!$_COOKIE['***']) {
    echo "<meta http-equiv=\"refresh\" content=\"0;url=../login.php\">";
}

if(isset($_GET['**']) == '******') {
    setcookie('***', '', time()-60, 'admin/');
}

?>`

Wooble
  • 87,717
  • 12
  • 108
  • 131
Paz
  • 101
  • 2
  • 13

6 Answers6

5

Set its expire time to backward ,it will unset the cookie

setcookie('cookiename', '', time()-3600);
Yogesh Suthar
  • 30,424
  • 18
  • 72
  • 100
3

set cookie in the past... like:

setcookie ("***", "username", time() - 3600);
GrandFelix
  • 41
  • 3
1

to unset cookie, you need to set your expire time to the past, like.

setcookie('your_cookie_name', '', time()-3600);
Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162
0

To delete a cookie always set its time in negative from the current time().

setcookie('nameofcookie', '', time()-3600);

This code sets your cookie persist time to negative so it automatically deletes.

Rohit Choudhary
  • 2,253
  • 1
  • 23
  • 34
0

// set the expiration date to one hour ago

 setcookie("cookiename","", time()-3600);
thumber nirmal
  • 1,639
  • 3
  • 16
  • 27
0
setcookie("cookie name", "", time()-3600); 
Sharique Ansari
  • 1,458
  • 1
  • 12
  • 22