Hwo do I make this Ban IP file work from a text file?

okay

<?php 
$banned_ip = array(); 
$banned_ip[] = '111.111.111.111'; 
$banned_ip[] = '111.111.111.112'; 
$banned_ip[] = '111.111.111.113'; 
$banned_ip[] = '111.111.111.114'; 

foreach($banned_ip as $banned) { 
    $ip = $_SERVER['REMOTE_ADDR']; 
    if($ip == $banned){ 
        echo "Here is where i would add my ban thing i got an idea :)"; 
        exit(); 
    } 
} 

?>

see that array? i made this thing but i don’t know how i could make it to where when i edit one file it edits the list of ip’s for the whole site cuz this is going to be one over 50 pages

like i put that code on every page and make a file called banned.txt when i put 111.111.111 ect. it will ban them without me having to go to every page and edit that one lil code

if this sounds confusing ask me more lol please help i have alot of spammers sending my e-cards on spamming sprees!

Thanks
raichu

you can have the array as a separate php script:


// save that as 'array.php'
<?php
$banned_ip[0] = '111.111.111.111'; 
$banned_ip[1] = '111.111.111.112'; 
$banned_ip[2] = '111.111.111.113'; 
$banned_ip[3] = '111.111.111.114';
?>

and then include that in your main script:

<?php

include 'array.php'

foreach($banned_ip as $banned) { 
    $ip = $_SERVER['REMOTE_ADDR']; 
    if($ip == $banned){ 
        echo "Here is where i would add my ban thing i got an idea <img src="images/smilies/happy.gif" border="0" alt="">"; 
        exit(); 
    } 
} 

?>

=)

thank you! i never thought of that! i’m learning PHP :slight_smile: