重定向无法正常工作
我的登录过程如下所示:
- 用户填写电子邮件并传递字段
- Ajax 将这些字段发送到
reg_system.php
。这是源代码 文件
。
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);
}
注意:wsurl之前声明过,并且是正确的值。
- 如果
$registration->signin()
返回true,它必须重定向到domain.com/?page=me
在调试过程中,我看到一切顺利并且 $registration->signin() 函数返回 true。但是在后期处理之后 Firebug XHR 显示此屏幕
然后重定向后
页面保持原样:在同一登录页面上。脚本不会重定向到任何地方..
我不知道什么会导致此问题,因为检查了整个调试过程近 10 倍时间。 PHP 在 header() 之前不输出任何内容。
My signin procedure looks like that:
- User fills email and pass fields
- Ajax sends these fields to
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.
- If
$registration->signin()
returns true it must redirect todomain.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
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. PHP doesn't output anything before header().
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用 JS 进行重定向。这可能比通过 php 完成更好。
Try using JS for your redirections. It might be better than doing it through php.