Redirect.php?url

Discussion in 'Programming' started by crazyboyami, Oct 19, 2010.

  1. #1
    Hi,

    I'm trying to code a little script which will allow me to redirect links from my website using a redirect script.

    I need the script to redirect like this:

    redirect.php?http://www.url.com

    i have tried this redirect.php?url=http://www.url.com however this has problems with the urls when redirected.

    if you need anymore information please ask.
     
    crazyboyami, Oct 19, 2010 IP
  2. max2010

    max2010 Greenhorn

    Messages:
    81
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #2
    try this:

    <?php
    header('Location: '.$_GET['url']);
    ?>
     
    max2010, Oct 19, 2010 IP
  3. SamT

    SamT Peon

    Messages:
    43
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    max2010, that wont work.
    You need to call the header() function and send the 301 header, then the Location header. Don't forget to exit after, if there is still more processing for it to after, the script will continue running and eating up server resources despite the fact that the client has already been redirected away and wont see the output of that page.

    <?php
    header('HTTP/1.1 301 Moved Permanently');
    header('Location ' . $_GET['url']);
    exit;
    ?>
    PHP:
     
    Last edited: Oct 20, 2010
    SamT, Oct 20, 2010 IP
  4. max2010

    max2010 Greenhorn

    Messages:
    81
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #4
    @SamT yep thanks I forgot :)
     
    max2010, Oct 20, 2010 IP
  5. deepakg

    deepakg Peon

    Messages:
    48
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi,

    Try this Code to Redirect your URL

    <?php 
    header("Location: http://www.redirecturl.com/"); 
    ?>[CODE][CODE]
    Code (markup):
    [/CODE][/CODE]
     
    deepakg, Oct 25, 2010 IP