Problems with cookies / MAMP / CodeIgniter

拈花ヽ惹草 提交于 2019-12-20 05:44:32

问题


I'm having a problem with reading cookies on localhost, using MAMP and Codeigniter.

I'm trying to ude a cookie to authenticate acess to an admin area. I can set the cookie (I see it on my browser - Chrome) but i'm not able to read it after doing that to grant the acess. I've already tried lots of configurations, but none works. I really need some help on this.

Those are the essencial parts of my code:

Here I set the cookie

$cookie = array(
    'name'   => 'login',
    'value'  => 'true',
    'expire' => '0',
    'secure' => TRUE
);
set_cookie($cookie);

Here I redirect the user to login page if there is no cookie and to control panel if the cookie is set

function login_redirect() {
    $this->load->helper('cookie');
    if (uri_string() == 'admin/controlpanel') {
        if ($this->input->cookie('login')) {
        } else {
            redirect('admin/');
        }
    }
    if (uri_string() == 'admin') {
        if ($this->input->cookie('login')) {
            redirect('admin/controlpanel');
        }
    }
}

OBS: all this code is in the admin_model

Any tips?

Thanks and sorry about my english. I hope I've made myself clear.


回答1:


Codeigniter has some problems with the Cookie and Session libraries when run on some localhost configurations. You'll spend hours trying to find out the particular problem with your setup. The best bet is to use generic PHP cookie/session when on localhost and use another library when in testing.

I appreciate that this is by no means the best solution but it's the best advice I can offer.



来源:https://stackoverflow.com/questions/5868177/problems-with-cookies-mamp-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!