問題描述
我有一個名為 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模板網!