If you send me a URL in the GET redirect to that URL

3

As the title of the post says if you send me a url I want to redirect to that url . How would you do it completely?

if (isset($_GET["URL"])) {
    header("Location: public_area.php?url=$actual_link");
}
    
asked by Serj 10.02.2016 в 21:59
source

2 answers

3

After checking if the other url exists, store it in a variable that you will then use to arm the redirection header. Also, use the exit method after placing the header, this way the current script stops and the redirect is sent to the new url.

if (isset($_GET["url"])) {
    $url = $_GET["url"];
    header("Location: $url");
    exit();
}

In case you do not want to use an additional variable, you can concatenate the value of the parameter directly to the header string:

if (isset($_GET["url"])) {
    header("Location: ".$_GET["url"]);
    exit();
}
    
answered by 10.02.2016 в 22:14
2

Take the value of the url after checking that it exists and using header () you add the url you want to redirect, when you finish it uses the exit () to finish the script:

if(isset($_GET['URL'])) {
   $url = $_GET['URL'];
   header('Location: ' .$url);
   exit();
}

You can also use the die () method to end the script

if(isset($_GET['URL'])) {
   $url = $_GET['URL'];
   header('Location: ' .$url);
   die();
}
    
answered by 10.02.2016 в 22:14