Get up to 80 % extra points for free! More info:

Discussion: PHP MVC - Can't delete cookie


:5/3/2017 10:09

Hello i'm building my own simple MVC framework. When I tried to create login page all worked - session all ok. But when I try to work with cookies, it doesn't work. Exactly deleting cookie don't work. :( Please help me, i can't find any solutions on google. File code where I'm trying to delete cookie:

class HomeController extends Controller {

    function __construct(){
        $this->view = 'testView';

    public function index($params){
            echo "cookie exists";
        } else{
                    setcookie('logged', true, time()+3600);

    public function logout($params){
        setcookie('logged', null, time()-3600);


My whole code


5/3/2017 10:09
David Capka team
Replies to
David Capka:5/3/2017 12:41

If you're not on local server, the problem can be your website is using pretty urls so you have to specify other parameters of the setcookie() method like this:

setcookie('logged', 'true', time() + 3600, '/', '', null, true);

Also notice specifying the last parameter to protect the cookies from being stolen using XSS attack.

However, I think you want to use sessions, we don't usually use cookies for logging in/out. Cookies can be used for permanent login, but not for the core mechanism.

Up Reply
5/3/2017 12:41
You can walk through a storm and feel the wind but you know you are not the wind.
To maintain the quality of discussion, we only allow registered members to comment. Sign in. If you're new, Sign up, it's free.

2 messages from 2 displayed.