Simple PHP Out Redirect

Discussion in 'PHP' started by ChristopherLeeMaher.Com, Jul 25, 2010.

  1. #1
    Hello,

    I am setting up a search engine and on the results page i have likes like this http://example.com/out.php?u={} how can i make it so http://ex.../ redirects to http://youtube.com/ Thanks,
     
    ChristopherLeeMaher.Com, Jul 25, 2010 IP
  2. Deacalion

    Deacalion Peon

    Messages:
    438
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    <?php
        header('Location: ' . $_GET['u']);
    ?>
    
    PHP:
     
    Deacalion, Jul 25, 2010 IP
  3. ChristopherLeeMaher.Com

    ChristopherLeeMaher.Com Guest

    Messages:
    185
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    what about if they goto the out.php file its a blank page how can i make it redirect to http://example.com/

    thanks,
     
    ChristopherLeeMaher.Com, Jul 25, 2010 IP
  4. Deacalion

    Deacalion Peon

    Messages:
    438
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Deacalion, Jul 25, 2010 IP
  5. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #5
    You might also want to validate $_GET['u'] (check if its actually an url etc.)
     
    danx10, Jul 25, 2010 IP
  6. Zeh.

    Zeh. Peon

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Actually that's simple:
    
    <?php
        if (!isset($_GET['u']) ||
            !filter_var($_GET['u'], FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED)) $_GET['u'] = 'http://example.com/';
        header('Location: ' . $_GET['u']);
    ?>
    
    PHP:
     
    Zeh., Jul 25, 2010 IP