I want to change the URL through PHP.
Something like window.location.href = "http://www.something.com"
in JavaScript.
I want the same thing but in PHP. How can I do it?
I want to change the URL through PHP.
Something like window.location.href = "http://www.something.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/");
exit;
Note that such call must be followed by exit
as to stop any other code from execution.
In case it errors out with "Headers already sent", refer to this answer
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.
?>
You could use:
echo '<script> window.location.href = "http://www.something.com"</script>';