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.
?>
精彩评论