我有一个名为 Accounts 的控制器,带有登录和注销视图.
I have a controller called Accounts, with the views signin and signout.
对应的函数如下:
function signin()
{
if (!empty($this->data))
{
//handle login
...
//save login to session
$this->Session->write('Account', $data["Account"]);
//redirect to previous page
???
}
}
function signout()
{
//delete login
$this->Session->delete('Account');
//redirect to previous page
???
}
如果用户转到 accounts/signin 它首先检查表单是否被提交 if(!empty($this->data)) 如果是,它会登录它们,如果不是,它会呈现登录表单.如果他们成功登录,我想将他们重定向到他们在登录页面之前所在的页面.
If the user goes to accounts/signin it first checks to see if the form is submited if(!empty($this->data)) if yes, it logs them in, if not it renders the signin form. If they do succesfully log in, I want to redirect them to the page they were at before the signin page.
最好的方法是什么?
我不认为我可以使用常规的 http 引荐来源网址,因为从技术上讲,引荐来源网址将始终是登录页面,因为他们转到 /signin,然后提交登录表单.因此,在提交表单时,引用者始终是 /signin.我想重定向到他们之前所在的位置.有意义吗?
I do not think I can user a regular http referrer because technically the referrer will always be the signin in page because they go to /signin, then submit the sign in form. So at the point where the form is submited the referrer is always /signin. I want to redirect to where they were before that. Does that make sense?
http://book.cakephp.org/view/430/referer
使用隐藏的 字段,该字段保存初始引用者并与登录数据一起提交.
Use a hidden <input> field that holds the initial referrer and gets submitted with the login data.
这篇关于登录后让用户返回上一页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
不能使用 'Object 作为类名,因为它是保留的Cannot use #39;Object as class name as it is reserved Cake 2.2.x(不能使用 Object 作为类名,因为它是保留的 Cake 2.2.x)
OAuth 重定向后会话丢失Session is lost after an OAuth redirect(OAuth 重定向后会话丢失)
Cakephp 3.x 中的分页排序Pagination Sort in Cakephp 3.x(Cakephp 3.x 中的分页排序)
CakePHP 多个应用程序的共享核心CakePHP Shared core for multiple apps(CakePHP 多个应用程序的共享核心)
在 CakePHP 3 上登录 [ Auth->identify() ] 始终为 falLogin [ Auth-gt;identify() ] always false on CakePHP 3(在 CakePHP 3 上登录 [ Auth-identify() ] 始终为 false)
致命错误:允许的内存大小为 134217728 字节已用尽Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)(致命错误:允许的内存大小为 134217728 字节已用尽