Take user back to previous page after logging in?(登录后让用户返回上一页?)
问题描述
我有一个名为 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.
这篇关于登录后让用户返回上一页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:登录后让用户返回上一页?
基础教程推荐
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01