PHP Redirect Script

Discussion in 'Noob Central' started by ndocoder, Jun 3, 2011.

  1. ndocoder

    ndocoder VIP

    Joined:
    Mar 10, 2011
    Messages:
    53
    Likes Received:
    10
    Trophy Points:
    0
    Location:
    San Diego
    Here is a handy little PHP Redirect script I wrote that you can use. It will take all of the URL arguments (everything after the ? in the URL) and rewrite them to your target domain. This is useful when setting up mailing domains and a lot of other things. Enjoy.


    PHP:
    <?php
    function dump($array)
    {
        echo 
    "<pre>" print_r($arraytrue) . "</pre>";
    }

    //dump($_SERVER);

    //parse the url string
        
    $params parse_url($_SERVER[REQUEST_URI]);

    //parse url paramters and put them into an array
        
    parse_str($params['query'], $output);

    //build args for the redirect link
        
    foreach ($output as $id => $value) {
            
    $args $args."&$id=$value";
        }

    //build complete url to redirect to
    //change the 'yourdomain.com' to your affiliate link or your tracking software
        
    $loco "http://yourdomain.com/?" $args;
        
    //dump($loco);

    header("Location: $loco");
    ?>
     

Share This Page