如果使用变量构建,则重定向到页面不起作用
为什么这不起作用并在 Firefox 中给出页面未正确重定向错误
$page_name = "home.php";
if (true) {
//none
} else {
header("location:http://mysite.com/pages/".$page_name);
die;
};
Why this does not work and gives page isnt redirecting properly error in firefox
$page_name = "home.php";
if (true) {
//none
} else {
header("location:http://mysite.com/pages/".$page_name);
die;
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试正确执行 - 该方法是惰性重定向:
请注意间距以及我已明确选择响应代码的事实。
虽然没有真正的原因导致您所做的事情不起作用,而且如果您设置
Location:
标头并设置 302 代码,PHP 也应该弄清楚您正在执行重定向,但它是最好总是正确地做,这样你就知道它应该有效。Try doing it properly - that method is the lazy redirect:
Note the spacing and the fact that I have explicitly chosen a response code.
While there is no real reason for what you have done not to work, and also PHP should figure out the fact that you are doing a redirect if you set a
Location:
header and set a 302 code, it's always best to do it properly so you know it should work.更改
并删除
if 语句末尾的分号。
结果:
如果这不起作用,还要更改标头调用以遵循 DaveRandom 的建议。
Change
to
and remove the semicolon at the end of the if statement.
Result:
If this doesn't work, also change the header calls to follow DaveRandom's advice.