Cookie/MAMP/CodeIgniter问题 [英] Problems with cookies / MAMP / CodeIgniter

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

问题描述

使用MAMP和Codeigniter在本地主机上读取Cookie时遇到问题.

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

我正在尝试通过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

Here I set the cookie

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

如果没有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:所有这些代码都在admin_model中

OBS: all this code is in the admin_model

有什么提示吗?

谢谢你,对我的英语感到抱歉.我希望我已经说清楚了.

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

推荐答案

在某些localhost配置上运行时,Codeigniter的Cookie和Session库存在一些问题.您将花费数小时来尝试找出设置中的特定问题.最好的选择是在localhost上使用通用的PHP cookie/会话,而在测试时使用另一个库.

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/CodeIgniter问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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