开发者

Problems with cookies / MAMP / CodeIgniter

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜