How to do redir.php?page=http://****.com

Discussion in 'PHP' started by ntesla123, Dec 3, 2011.

  1. #1
    I have tried to make a redirect like this: redir.php?page=http://****.com
    
    <?php
    if(is_file($_GET['page'])){$page = $_GET['page'];}
    else{$page = "DEFAULT.php";}
    header("Location: ".$page);
    ?>
    
    Code (markup):
    But I only get:

    What should I do?
     
    ntesla123, Dec 3, 2011 IP
  2. rainborick

    rainborick Well-Known Member

    Messages:
    424
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Neither is_file() nor file_exists() is designed to test URLs. They are for checking the local files on the server. If you want to test a URL, you should probably use cURL and look for a response code of 200. Good luck!
     
    rainborick, Dec 3, 2011 IP
  3. ChefGaby

    ChefGaby Active Member

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    96
    #3
    See if this works:
    if($_GET['page']) {
        if(file_get_contents($page)) {
            header("Location: ".$page); die();
        } else {
            header("Location: /DEFAULT.php"); die();
        }
    } else {
        echo "Please specify a url";
        //or
        //header("Location: /DEFAULT.php"); die();
    }
    PHP:
     
    ChefGaby, Dec 6, 2011 IP