通过 PHP 更改 URL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/2764301/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change the URL through PHP
提问by Nitz
I want to change the URL through PHP.
我想通过 PHP 更改 URL。
Something like window.location.href = "http://www.something.com"in JavaScript.  
类似于window.location.href = "http://www.something.com"JavaScript 中的东西。  
I want the same thing but in PHP. How can I do it?
我想要同样的东西,但在 PHP 中。我该怎么做?
回答by Sarfraz
回答by richsage
You could use the header() command:
您可以使用 header() 命令:
<?php
  header("Location: http://www.example.com/");
?>
回答by Glycerine
<?php
header('Location: http://www.example.com/');
?>
Make sure there is nothingabove the line outputted, otherwise it will fail.
确保输出的行上方没有任何内容,否则会失败。
回答by Mystical
You could use ob_startalong with the headerfunctionin order to prevent redirection errors like so:
您可以将ob_start与标头函数一起使用,以防止重定向错误,如下所示:
<?php
   ob_start(); // Starts Output Buffering 
   header(/*Your redirection's location*/); // Redirects user to given location.
?>

