PHP Gurus, Please Help with my script.

by 7 replies
8
Hi. I have made a simple PHP script to check for banned IPs and redirect the banned ones to a certain URL, then redirect the other non banned IPs to a different URL. What I am now trying to do is make the script be able to randomly redirect the non banned ones to one of 5 or so URLs that I have.

For example. I have a number of different affiliate offers for a free credit report and I want to send each non banned IPs to a randomly chosen URL so each affiliate offer will get some traffic and hopefully some sales.

Below is the code I have already written. If someone could help show me how to make it do the random URL thing, I would appreciate it.

Code:
<?php 
$banned_ip = array(); 
$banned_ip[] = '204.96.148.3'; 
$banned_ip[] = '205.162.217.141'; 
foreach($banned_ip as $banned) 
{  
    $ip = $_SERVER['REMOTE_ADDR']; 
    if($ip == $banned)
    {  
        header("location: hxxp://you-are-banned.com"); 
        die();//abort the script on redirect. just in case.
    }
}  
//if we got this far, their IP is obviously not banned
//this is where I would like it to have numerous URLs to randomly send each visitor to one of them
header("location: hxxp://freecreditreport1.com"); 
?>
#programming #gurus #php #script
  • This should do the trick.

    PHP Code:
    $banned_ip_list = array(
    '204.96.148.3',
    '205.162.217.141'
    );

    if (
    in_array($_SERVER['REMOTE_ADDR'], $banned_ip_list))
    {
        
    header('location: http://you-are-banned.com');
        exit();
    }
    else
    {
        
    $destination_list = array(
        
    'http://www.site1.com',
        
    'http://www.site2.com',
        
    'http://www.site3.com',
        
    'http://www.site4.com',
        
    'http://www.site5.com',
        );

        
    $key rand(0count($destination_list) - 1);

        
    header('location: '.$destination_list[$key]);
        exit();

  • Installer for flash builder not working, Need Help...
    • [1] reply
    • tufats... you need to start a new thread
  • Banned
    The script specified by the gcornelisse is correct and hope it works if you have tried it
  • Gary, that was very elegantly coded. I can learn more from this forum.

    Thanks

    Martin
    • [1] reply
    • Nice clean code there Gary..

      Well done!!

      He's laid it out in such a way that you could extend this script without too much hassle..

      Some good coding..

      Bruce
  • Just a word of warning..

    If anyone is thinking of putting in a list of search engine IP address into Gary's code, so that search engines see one page and othe see other pages, be very careful..

    Although IP cloaking is conceptually quite simple (the code above can work), the search engine use so many IP addresses that the average person can't keep up.
    Thats while there are some very expensive cloaking apps such as Fantomas ShadowMasker that do a very good job on this..

    Just my 2cents worth of warning..

    Take care

    Bruce

Next Topics on Trending Feed

  • 8

    Hi. I have made a simple PHP script to check for banned IPs and redirect the banned ones to a certain URL, then redirect the other non banned IPs to a different URL. What I am now trying to do is make the script be able to randomly redirect the non banned ones to one of 5 or so URLs that I have. For example. I have a number of different affiliate offers for a free credit report and I want to send each non banned IPs to a randomly chosen URL so each affiliate offer will get some traffic and hopefully some sales.