Cookie / MAMP / Codeingiter的问题 [英] Problems with cookies / MAMP / Codeingiter

查看:160
本文介绍了Cookie / MAMP / Codeingiter的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用MAMP和Codeigniter读取localhost上的Cookie时遇到问题。

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

我试图ude一个cookie来验证管理区域的访问权限。我可以设置cookie(我在我的浏览器 - Chrome上看到),但我无法读取它,以授予访问权限。我已经尝试了很多配置,但没有工作。我真的需要一些帮助。

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:

cookie

$ cookie = array(

'name'=>'login',

'value'= >'true',

'expire'=>'0',

'secure'=> TRUE

);

set_cookie($ cookie);

这里我将用户重定向到登录页面是没有cookie,并且控制面板如果设置了cookie

function login_redirect(){0047
$ this-> load-> helper ');

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');

}

}

}

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:所有这些代码都位于admin_model

OBS: all this code is in the admin_model

任何提示?

感谢并对不起我的英语。

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

推荐答案

Codeigniter在某些localhost配置上运行时,Cookie和会话库有一些问题。您将花费数小时的时间来了解您的设置中的特定问题。最好的办法是在localhost上使用通用的PHP cookie / session,并在测试时使用另一个库。

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.

这篇关于Cookie / MAMP / Codeingiter的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆