du8828 2012-05-29 23:36
浏览 30
已采纳

CakePHP Auth.redirect没有被写入

I have followed the authentication tutorial in the cakephp documentation and created a working login system.

One thing I'm trying to do is have the user redirected to the action they were trying to access initially when not logged in, after they complete login.

I believe the page they were visiting is supposed to be written to Auth.redirect within the session by the startup function in the Auth component, however this doesn't appear to be working.

In my users controller I have added the following to the beforefilter:

$this->Auth->allow('add', 'login');

Therefore when trying to access the edit action I'm redirected automatically to the login action.

In the login action, I've included:

debug($this->Session->read());
debug($this->referer());

This is outputting the session information, and in this session there is no mention of Auth.redirect so neither the Auth function or myself is unable to use this to redirect the user with.

I've tried using $this->referer but for some reason when being redirected automatically by the auth function the referer isn't being tracked either.

Does anyone know a reason why auth.redirect might not be being written and why $this->referer isn't being populated when redirected by the auth function?

I must note I am on a windows machine using WAMP. However my add action redirects to login after success and debug($this->referer()); picks up the redirect URL when this occurs so the headers must be working fine.

Further Notes:

I've identified the issue with CakePHP by looking through the sessions stored in the database.

It seems that the auth.redirect is stored in the session, however for some reason a new session is generated when the user is redirected clearing the previous data.

Is there anyway to stop CakePHP creating new session ids for users?

  • 写回答

1条回答 默认 最新

  • duanqian3953 2012-05-30 19:24
    关注

    I've identified the issue as to why auth.redirect wasn't working.

    I had set a custom session cookie name in core.php, for some reason the session component doesn't work with the custom cookie name and therefore creates a new session on every page.

    If you are experiencing problems with sessions and you have a custom session cookie name, reset it to default and it will work.

    I will be submitting this as a bug to CakePHP.

    Further Note

    I identified the issue was occuring because of a . in the cookie name, without this . the custom cookie name performs as it should.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集