Unset cookies php

前端 未结 8 1891
萌比男神i
萌比男神i 2021-01-04 09:28

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

if((isset($_POST[\"remember_me\"]))&&($_POST[\"remember_me\"]==1))
    {
    setcookie(\'email         


        
相关标签:
8条回答
  • 2021-01-04 10:00

    You need to set your expire time to the past, e.g.

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

    Also you should be using an Absolute URI for your header('Location:' ....).

    0 讨论(0)
  • 2021-01-04 10:05
    setcookie('cookiename', '', time()-3600);
    
    0 讨论(0)
  • 2021-01-04 10:11

    either use the superglobal _COOKIE variable:

    unset($_COOKIE['mycookiename']);
    

    or call setcookie() with only the cookies name

    setcookie('mycookiename');
    

    To reset your cookies at logout use:

    setcookie('pass');
    setcookie('email');
    

    For you login check:

    if(
      isset($_POST["remember_me"]) &&
      $_POST["remember_me"]==1  &&
      $_COOKIE['pass'] != NULL &&
      $_COOKIE['email'] != NULL &&
    )
    
    0 讨论(0)
  • 2021-01-04 10:13

    To unset cookies in PHP, simply set their expiry time to a time in the past. For example:

    $expire = time() - 300;
    setcookie("email", '', $expire);
    setcookie("pass", '', $expire);
    
    0 讨论(0)
  • 2021-01-04 10:17

    try this

        setcookie ("email", "", time() - 3600);
        setcookie ("pass", "", time() - 3600);
    
    0 讨论(0)
  • 2021-01-04 10:18

    In Chrome and IE8+ at least, the following will remove the cookie from the browser. It will not be reflected in the $_COOKIE array until the page is reloaded however.

    setcookie('cookiename','',0,'/',$cookieDomain)

    you may be able to leave off a few parameters here, but the important thing is you are setting an empty string, and that removes the cookie from the browser.

    0 讨论(0)
提交回复
热议问题