2012-06-26 16:38
浏览 51

codeigniter cookie helper与会话助手相结合

Is it possible to run both session and cookie helpers? Cause I am trying and I can't get a cookie to set for the life of me, no matter what method I try either falling CI's docs to the letter and doing it there way or attempting to work with cookies through native php alone. Either way I try cookies will not set.

I have tried to set them like:

$this->input-set_cookie('AutoRemember', $mID.'-'.$hashbrown, $shortlife);
setcookie('AutoRemember', $mID.'-'.$hashbrown, $shortlife);

and I have tried to work with them like

echo $this->input->cookie('AutoRemember');
echo $_COOKIE['AutoRemember'];

the cookie helper is auto loaded just as is the session one, so they are loaded. session helper works like a charm, but the cookies I got nothing but a headache. All I want to do is set a cookie so I can have a "remember me" function on my site, and what should be a 5 minute deal to do, has taken me hours of various ways of passing it either by setting something for a view to pick up so it can set it in a view, or setting it in the controller and nothing.

Doesn't appear to be a browser issue either as both Chrome, and FireFox seem to not have a cookie getting stored anywhere.

So is it something with using both sessions and cookies or is codeigniter garbage when it comes to setting a cookie and kills the effort no matter which way you try.

图片转代码服务由CSDN问答提供 功能建议

是否可以运行会话和cookie帮助程序? 因为我正在尝试,我不能得到一个cookie来为我的生活设置,无论我尝试将CI的文档降到信中并在那里做或者尝试通过本机php单独使用cookie。 无论哪种方式我尝试cookie都不会设置。


  $ this-> input-set_cookie('AutoRemember',$ mID。'  - '。$ hashbrown,$ shortlife); 
setcookie('AutoRemember',$ mID .'-'。$ hashbrown,$ shortlife); 


  echo $ this-> input-> cookie('AutoRemember'); 
echo $ _COOKIE ['AutoRemember'  ]; 

cookie helper是自动加载的,就像会话一样,因此它们被加载。 会话助手就像一个魅力,但我得到的饼干只是一个令人头疼的问题。 我想要做的就是设置一个cookie,这样我就可以在我的网站上有一个“记住我”的功能,应该做5分钟的交易,花了几个小时的时间通过设置一些东西来传递它 查看以便可以在视图中设置它,或者在控制器中设置它,什么也不设置。

Chrome和FireFox看起来似乎都不是浏览器问题 没有cookie存储在任何地方。

所以它是使用会话和cookie的东西,或者是在设置cookie并且无论你以哪种方式杀死努力时都是codeigniter垃圾 试试。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douchungu0859 2012-06-26 17:00

    Looking through some of the Expression Engine code (an app shipped by Ellis Labs that uses CI) they are calling the PHP native setcookie function in their set_cookie function, so perhaps this is the way to go.

    Looks like there should be no problem having the cookie helper running in tandem with the Session library. That said it's worth noting the Session class is calling setcookie directly rather than using the cookie helper (way to reuse code CI!).

    In general, calling the PHP function setcookie should bypass any CI stuff and work no matter what, so if that isn't working maybe something else is going on. Best bet is probably to start with setcookie and try to get that working.

    Check the return value from setcookie, if it's false output has already been started and that's why it isn't working; could be the same issue you're running into trying the CI cookie helper too.

    解决 无用
    打赏 举报

相关推荐 更多相似问题