开发者

Change the URL through PHP

开发者 https://www.devze.com 2022-12-29 06:00 出处:网络
I want to change the URL through PHP. Something like window.location.href = \"http://www.somet开发者_JAVA百科hing.com\" in JavaScript.

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

精彩评论

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