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

Discussion: PHP MVC - Can't delete cookie

Activities
Avatar

Member
Avatar
: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:

<?php
class HomeController extends Controller {

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


    public function index($params){
        if(isset($_COOKIE['logged'])){
            echo "cookie exists";
        } else{
            if($_POST){
                if(isset($_POST['rr'])){
                    setcookie('logged', true, time()+3600);
                }
            }
        }
    }

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

}

My whole code

Thanks.

 
Reply
5/3/2017 10:09
Avatar
Replies to
David Capka Hartinger: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, '/', '.yourdomain.com', 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.
Avatar
TarasZabrodskiy:10/17/2023 11:18

When I needed stock photos related to iso tank images I turned to this online service, and I was not disappointed. The collection was comprehensive and diverse, offering images that perfectly suited my project requirements. The high-resolution images were of top-notch quality, and the platform's search functionality made it a breeze to find the specific ISO tank images I needed. This service exceeded my expectations, and I wholeheartedly recommend it to anyone seeking 'ISO tank' images for their projects.

 
Up Reply
10/17/2023 11:18
Avatar
yokhama67
Member
Avatar
yokhama67:30. January 6:26

Hello Everyone! I want to suggest you to discover the future of rail travel at Online Speedometer. Our website is dedicated to providing real-time insights into train speeds and performance. Whether you're a commuter, enthusiast, or industry professional, stay informed about the latest advancements and speed data. TrainSpeed.com is your one-stop destination for all things related to the velocity and efficiency of trains.

 
Up Reply
30. January 6:26
To maintain the quality of discussion, we only allow registered members to comment. Sign in. If you're new, Sign up, it's free.

4 messages from 4 displayed.