简体   繁体   English

重定向无法正常工作

[英]Redirect doesn't work properly

My signin procedure looks like that: 我的登录过程如下所示:

  • User fills email and pass fields 用户填写电子邮件并通过字段
  • Ajax sends these fields to reg_system.php . Ajax将这些字段发送到reg_system.php Here is source code of file 这是文件的源代码

.

if (isset($_POST['formID']) && !empty($_POST['formID'])) {
    $registration = new registration($db);
    $forms = array('signup_form', 'signin_form', 'tcr_form');
    if (in_array($_POST['formID'], $forms)) {
        $redirect = "";
        switch ($_POST['formID']) {
            case 'signin_form':
                if ($registration->signin())
                    $redirect ='me';
                break;
            case 'tcr_form':
            case 'signup_form':
                $registration->signup();
                break;
        }
    }
    if (!empty($redirect))
         header("Location:".wsurl."?page=".$redirect); 
}

Note : wsurl declared before, and is right value. 注意 :wsurl之前声明过,并且是正确的值。

  • If $registration->signin() returns true it must redirect to domain.com/?page=me 如果$registration->signin()返回true,则必须重定向到domain.com/?page=me

During debug process, I see that all goes well and $registration->signin() function returns true.But right after post process Firebug XHR shows this screen 在调试过程中,我看到一切顺利,并且$ registration-> signin()函数返回true。但是在后期处理Firebug XHR之后立即显示此屏幕

在此处输入图片说明

Then after redirection 然后重定向之后 在此处输入图片说明

Page stays as it is: on the same login page. 页面保持原样:在同一登录页面上。 Script doesn't redirect to anywhere.. 脚本不会重定向到任何地方。

I don't know what can cause this, because checked whole debug process nearly 10x time. 我不知道是什么原因造成的,因为检查整个调试过程的时间接近10倍。 PHP doesn't output anything before header(). PHP在header()之前不输出任何内容。

Try using JS for your redirections. 尝试使用JS进行重定向。 It might be better than doing it through php. 它可能比通过php更好。

<script type="text/javascript">
<!--
window.location = <?php echo wsurl."?page=".$redirect; ?>;
//-->
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM