开发者

Change the URL through PHP

I want to change the URL through PHP.

Something like window.location.href = "http://www.somet开发者_JAVA百科hing.com" in JavaScript.

I want the same thing but in PHP. How can I do it?


You can use the header function for that:

header("LOCATION: http://www.something.com");


You could use the header() command:

<?php
  header("Location: http://www.example.com/");
?>


<?php
header('Location: http://www.example.com/');
?>

Make sure there is nothing above the line outputted, otherwise it will fail.


You could use ob_start along with the header function in order to prevent redirection errors like so:

<?php
   ob_start(); // Starts Output Buffering 
   header(/*Your redirection's location*/); // Redirects user to given location.
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜