让用户在登录后回到上一页? [英] Take user back to previous page after logging in?

查看:84
本文介绍了让用户在登录后回到上一页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



相应的功能如下所示:

  function signin()
{
if(!empty($ this-> data))
{
//句柄登录
...
//保存登录到会话
$ this-> Session-> write('Account',$ data [Account]);
//重定向到上一页
???
}
}

function signout()
{
//删除登录
$ this-> Session-> delete '帐户');
//重定向到上一页
???
}



如果用户转到 accounts / signin 它首先检查表单是否提交 if(!empty($ this-> data))如果是,它会记录它们,if不是它呈现登录形式。如果他们成功登录,我想将他们重定向到他们在登录页面之前的页面。



最好的方法是什么?



编辑



我认为我无法使用常规http引荐来源网址,因为将始终是登录页面,因为他们去 / signin ,然后提交登录表单。因此,在提交表单的地方,引荐来源始终为 / signin 。我想重定向到他们之前的地方。这是否有意义?

解决方案

http://book.cakephp.org/view/430/referer



使用隐藏的 < input> 字段,用于保存初始引荐来源网址,并与登录数据一起提交。


I have a controller called Accounts, with the views signin and signout.

The corresponding functions look like this:

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
    ??? 
}

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.

Whats the best way to do that?

Edit:

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.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆