1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Redirect by IP?

Discussion in 'Web Design' started by hawke, Apr 17, 2009.

  1. hawke

    hawke Power Member

    Joined:
    Nov 14, 2008
    Messages:
    644
    Likes Received:
    533
    Location:
    Ohio
    Is there a way to redirect an AM with Known network IP address to show a different webpage than what your running one of their Offers on?

    I want to run an offer on my incentive network, but the offer doesn't allow it.

    I can blank/fake the referer, but I want the AM to see that it's comming from my domain I have registered with them. I've seen IP list's for some of the CPA Networks, and thought maybe I could redirect them by their IP address to a second copy of my site say an INDEX2.html or something.

    If it is at all possible, I need some pointers on how to start it. Thanks.
     
  2. drdankmendez

    drdankmendez Junior Member

    Joined:
    May 30, 2008
    Messages:
    194
    Likes Received:
    316
    Location:
    In front of my computer
    This could be accomplished using PHP. Pretty much you would check the IP, if it matched the IP of the network then you would redirect to your 'clean' page. If its not the IP of the network display your 'dirty' page.

    On your dirty page you could add this code to the top of your page:
    Code:
    <?php
    $networks_ip = array('55.55.55.55', '66.66.66.66', '77.77.77.77');
    $visitors_ip = $_SERVER['REMOTE_ADDR'];
    
    if (in_array($visitors_ip, $networks_ip)){
    	header("Location: http://www.yourCleanSite.com");
    }
    ?>
    The first line builds an array of the networks IP addresses, you simply put the ip addresses in quotes and seperated by a comma (no trailing comma).

    The second line grabs the current visitors IP address and stores it in the "$visitors_ip" variable.

    The next lines are a simple if statement that checks to see if the "$visitors_ip" exists in the array of network IP addresses. If it does then it will redirect using the header function. If the visitors ip is not contained in the array, then nothing will happen and the page will display.

    Hope this helps.
     
    • Thanks Thanks x 1
  3. bpaw

    bpaw Junior Member

    Joined:
    Aug 9, 2008
    Messages:
    175
    Likes Received:
    48
    Home Page:
    Look into mod_rewrite. Most web hosts have it installed already.