PHP Gurus, Please Help with my script.

7 replies
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"); 
?>
#gurus #php #script
  • Profile picture of the author gcornelisse
    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();

    {{ DiscussionBoard.errors[353385].message }}
  • Profile picture of the author tufats
    Installer for flash builder not working, Need Help...
    {{ DiscussionBoard.errors[353629].message }}
    • Profile picture of the author gcornelisse
      tufats... you need to start a new thread
      {{ DiscussionBoard.errors[353866].message }}
  • Profile picture of the author Jenniferlinn
    Banned
    The script specified by the gcornelisse is correct and hope it works if you have tried it
    {{ DiscussionBoard.errors[361690].message }}
  • Profile picture of the author thehypnoguy2
    Gary, that was very elegantly coded. I can learn more from this forum.

    Thanks

    Martin
    {{ DiscussionBoard.errors[388922].message }}
    • Profile picture of the author Bruce Hearder
      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
      {{ DiscussionBoard.errors[443825].message }}
  • Profile picture of the author Bruce Hearder
    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
    {{ DiscussionBoard.errors[445426].message }}

Trending Topics