Cookie is not deleted - PHP

0

I do not know the error I am making when creating a class, but I can not delete the cookie with my class.

public function cookie($name, $value = 'nome', $expire = NULL, $path = '/', $domain = NULL, $secure = FALSE, $httponly = TRUE) {
                setcookie($name, $value, $expire, $path, $domain, $secure, $httponly);
                return $this;
        }

public function delete($name){

            unset($_COOKIE[$name]);
            // empty value and expiration one hour before
            setcookie($name, NULL, -1);
            //return var_dump($_COOKIE);
        }

$cs->cookie('meu', 'sd', time()+1800);
$cs->delete('meu');

I do not know why in my browser the cookie is not deleted, what am I doing wrong?

    
asked by anonymous 27.03.2015 / 00:21

1 answer

1

After testing, here's the code to work:

function cookie($name, $value = 'nome', $expire = NULL, $path = '/', $domain = NULL, $secure = FALSE, $httponly = TRUE) {
                setcookie($name, $value, $expire, $path, $domain, $secure, $httponly);
                //return $this;
        }

function delete($name, $value = 'nome', $expire = NULL, $path = '/', $domain = NULL, $secure = FALSE, $httponly = TRUE) {
            unset($_COOKIE[$name]);
            setcookie($name, $value, $expire, $path, $domain, $secure, $httponly);
        }

cookie('omeucookie', 'sd', time()+1800);
delete('omeucookie', 'sd', 1);

In order to delete the cookie you need to send tb its value (sd) and path (/) that you defined previously.

    
27.03.2015 / 00:30