A
A
Alexander2016-07-05 16:24:28
PHP
Alexander, 2016-07-05 16:24:28

Removing cookies in php?

Guys, good cool day!
In general, there is an authorization page /login
. You can go to it by clicking on the link in the header from any page of the site.
After authorization of the user, you need to redirect to the previous page (the one from which you went).
To do this, I create cookies at the very beginning of the file.

<?
if (!isset($_COOKIE['prev_addr'])){
    
    setcookie("prev_addr",$_SERVER["HTTP_REFERER"],time()+3600,"/");
}

?>

Then at the bottom, if the user is authorized, I overwrite cookies and redirect to the previous page.
<?
    global $USER;
    if ($USER->IsAuthorized()) {        
        $temp = $_COOKIE['prev_addr'];
        setcookie("prev_addr","",time()-10000);
        LocalRedirect($temp);        
    }  
    ?>

But the cookie is not removed.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2016-07-05
@AVEN1Q

In general, it can be useful to someone.
Weird. Did it before - didn't work. Thanks guys ;)

if (!isset($_COOKIE['prev_addr'])){
    
    setcookie("prev_addr",$_SERVER["HTTP_REFERER"],time()+3600,"/");
}

global $USER;
    if ($USER->IsAuthorized()) {        
        $temp = $_COOKIE['prev_addr'];
        setcookie("prev_addr","",time()-3600,"/");
        //unset($_COOKIE['prev_addr']);
        LocalRedirect($temp);        
    }

K
Kirill Ushakov, 2016-07-05
@Bellicus

And even better, as you set the cookie, delete it, only with a minus sign:
setcookie("prev_addr","",time()-3600,"/");

A
Andrey Pavlenko, 2016-07-05
@Akdmeh

When deleting, you also need to specify the path setcookie("prev_addr","",time()-10000, '/');
Check.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question