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 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘