简体   繁体   English

PHP,重定向到另一个页面

[英]PHP, redirect to another page

How in a PHP script do I redirect to another page? 如何在PHP脚本中重定向到另一个页面? I tried header , but this didn't work since before my header() statement is an echo. 我尝试过header ,但是这在我的header()语句是echo之前没有用。

This, I do not want to use: 这个,我不想用:

echo "<meta http-equiv='refresh' content='1;URL=?".$link."'>"; 
  • Use ob_start() to delay the printing, and use header(), or 使用ob_start()来延迟打印,并使用header()或
  • Redirect using Javascript, this can be done anywhere in the page, or 使用Javascript重定向,这可以在页面的任何地方完成,或者
  • Rewrite your code so that you know early on, before anything is printed, whether you want a redirect. 重写您的代码,以便在打印任何内容之前及早知道您是否需要重定向。

You would want to do the following: 您可能希望执行以下操作:

header('Location: http://www.someURL.com');

But this must be done before anything is dropped to the output steam. 但是必须在将任何东西放到输出蒸汽之前完成。 Also you would not want to use 你也不想使用

echo "<meta http-equiv='refresh' content='1;URL=?".$link."'>"; 

As it would force the browser to reload your page, effectively rendering it useless if the user is trying to click a link or type something just as it refreshes. 因为它会强制浏览器重新加载页面,如果用户尝试单击链接或在刷新时键入内容,则有效地使其无效。

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

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