Need help on redirect php.

Discussion in 'PHP' started by AlecTheWebmaster, Jan 20, 2008.

  1. #1
    Hey,

    I've seen this used on alot of sites,

    http://yourdomain.com/external.php?url=http://www.redirectsite.com

    goes to

    http://redirectsite.com

    And anything you put into the ?url= goes to it.

    and when you go to the external.php, it says:

    'You are being redirected to (site url)'.

    Whats the code for this?

    Thanks,
    Alec
     
    AlecTheWebmaster, Jan 20, 2008 IP
  2. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #2
    Easy

    Just use something like,

    
    <?php
    
    $seconds = 3; // set the time to redirect in
    
    $url = $_GET['url'];
    echo "You are being sent to $url in $seconds";
    header("Refresh:$seconds URL=$url");
    ?>
    
    PHP:
     
    HuggyStudios, Jan 20, 2008 IP
  3. junandya

    junandya Member

    Messages:
    79
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #3
    Is there a way to get current URL automatically?, let say in this case if the current page is http://www.redirectsite.com/news.php.

    
    //this is the current page that i type manually
    $url="http://www.redirectsite.com/news.php";
    //this is the link to the next page,which i can go back again to this page (current page) base on $url
    echo "<A href=\"www.redirectsite.com/login.php?url=$url\">Login</A>";
    
    PHP:
     
    junandya, Jan 21, 2008 IP
  4. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #4
    Try this:
    $url = $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
    PHP:
     
    greatlogix, Jan 21, 2008 IP