PHP IP Ban/Redirect. Can you help with my script?

Status
Not open for further replies.

X_X_ROB_X_X

Banned
Jun 11, 2007
60
1
0
USA
www.totaldetails.info
Im in need of a little help with my php script if anyone has a bit of time. Simply put what i'm attempting to do is have the php script look at every person's IP as they come to my page. If their IP is in the banned_ip list i'm wanting to redirect that person to the first URL ( Yahoo! ).
If their IP is not in the list I want to redirect these people to the second URL in the script ( Google ).

It's basically a php IP ban/redirect script. I have tried it on my host the way it is written and added my own IP to the banned list and it kept sending me to the 2nd URL when it should have sent me to the 1st. I'm lost. I'm a complete PHP newb guys so please keep the laughing and rude comments to a minimum, lol.

Anyways i'd appreciate any and all help I can get. Below is my code.
Code:
<?php 
$banned_ip = array(); 
$banned_ip[] = '204.96.148.3'; 
$banned_ip[] = '205.162.217.141'; 
$banned_ip[] = '209.62.82.14'; 
$banned_ip[] = '24.7.101.103'; 
$banned_ip[] = '65.31.130.2'; 
$banned_ip[] = '68.168.78.226'; 
$banned_ip[] = '68.205.75.110'; 
$banned_ip[] = '69.36.158.35'; 
$banned_ip[] = '70.173.198.69'; 
$banned_ip[] = '70.97.122.18'; 
$banned_ip[] = '71.189.157.53'; 
$banned_ip[] = '71.230.54.244'; 
$banned_ip[] = '74.52.245.146'; 
$banned_ip[] = '76.90.3.205'; 
$banned_ip[] = '24.20.251.76'; 
$banned_ip[] = '68.83.254.243'; 
$banned_ip[] = '69.2.27.10'; 
foreach($banned_ip as $banned) {  
    $ip = $_SERVER['REMOTE_ADDR']; 
    if($ip == $banned){  
        header("location: hxxp://yahoo.com"); //link is posted with xx so it will show up correctly in this post
}
else
{
        header("location: hxxp://google.com"); //link is posted with xx so it will show up correctly in this post
        exit();  
    }  
}  
 
?>
 


Im in need of a little help with my php script if anyone has a bit of time. Simply put what i'm attempting to do is have the php script look at every person's IP as they come to my page. If their IP is in the banned_ip list i'm wanting to redirect that person to the first URL ( Yahoo! ).
If their IP is not in the list I want to redirect these people to the second URL in the script ( Google ).

It's basically a php IP ban/redirect script. I have tried it on my host the way it is written and added my own IP to the banned list and it kept sending me to the 2nd URL when it should have sent me to the 1st. I'm lost. I'm a complete PHP newb guys so please keep the laughing and rude comments to a minimum, lol.

Anyways i'd appreciate any and all help I can get. Below is my code.
Code:
<?php 
$banned_ip = array(); 
$banned_ip[] = '204.96.148.3'; 
$banned_ip[] = '205.162.217.141'; 
$banned_ip[] = '209.62.82.14'; 
$banned_ip[] = '24.7.101.103'; 
$banned_ip[] = '65.31.130.2'; 
$banned_ip[] = '68.168.78.226'; 
$banned_ip[] = '68.205.75.110'; 
$banned_ip[] = '69.36.158.35'; 
$banned_ip[] = '70.173.198.69'; 
$banned_ip[] = '70.97.122.18'; 
$banned_ip[] = '71.189.157.53'; 
$banned_ip[] = '71.230.54.244'; 
$banned_ip[] = '74.52.245.146'; 
$banned_ip[] = '76.90.3.205'; 
$banned_ip[] = '24.20.251.76'; 
$banned_ip[] = '68.83.254.243'; 
$banned_ip[] = '69.2.27.10'; 
foreach($banned_ip as $banned) {  
    $ip = $_SERVER['REMOTE_ADDR']; 
    if($ip == $banned){  
        header("location: hxxp://yahoo.com"); //link is posted with xx so it will show up correctly in this post
}
else
{
        header("location: hxxp://google.com"); //link is posted with xx so it will show up correctly in this post
        exit();  
    }  
}  
 
?>

You need to get the else statement out of the loops since there's more than one IP you're checking(unless it's the first IP, the else is called and you get redirected)


Code:
<?php 
$banned_ip = array(); 
$banned_ip[] = '204.96.148.3'; 
$banned_ip[] = '205.162.217.141'; 
$banned_ip[] = '209.62.82.14'; 
$banned_ip[] = '24.7.101.103'; 
$banned_ip[] = '65.31.130.2'; 
$banned_ip[] = '68.168.78.226'; 
$banned_ip[] = '68.205.75.110'; 
$banned_ip[] = '69.36.158.35'; 
$banned_ip[] = '70.173.198.69'; 
$banned_ip[] = '70.97.122.18'; 
$banned_ip[] = '71.189.157.53'; 
$banned_ip[] = '71.230.54.244'; 
$banned_ip[] = '74.52.245.146'; 
$banned_ip[] = '76.90.3.205'; 
$banned_ip[] = '24.20.251.76'; 
$banned_ip[] = '68.83.254.243'; 
$banned_ip[] = '69.2.27.10'; 
foreach($banned_ip as $banned) 
{  
    $ip = $_SERVER['REMOTE_ADDR']; 
    if($ip == $banned)
    {  
        header("location: hxxp://yahoo.com"); //link is posted with xx so it will show up correctly in this post
        die();//abort the script on redirect. just in case.
    }
}  
//if we got this far, their IP is obviously not banned
header("location: hxxp://www.google.com"); 
?>
 
Status
Not open for further replies.