沃梦达 / 编程问答 / php问题 / 正文

登录后让用户返回上一页?

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.

这篇关于登录后让用户返回上一页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:登录后让用户返回上一页?

基础教程推荐