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?
php if (! $_GET["name"] && $_GET["id"]) { // perform MySQL query to get name based on id header("Location: http://www.something.org/zzz"); die(); // stop execution of this page } // if we got here, $_GET["name"] is set, so do whatever this script is supposed to do. ?> NOTE: The above .
<? php if (! preg_match("/^(http|ftp):/", $_POST['url'])) { $_POST['url'] = 'http://'.$_POST['url']; } $url = $_POST['url']; ?> This code will add http:// to the URL if it's not there.
Answer: Use the PHP $_SERVER Superglobal Variable You can use the $_SERVER built-in variable to get the current page URL in PHP. The $_SERVER is a superglobal variable, which means it is always available in all scopes.
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/");
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With