here is the practical use of an array contained with in a file to keep dirt bags from a page or a site and send them some were else
this is the file dirtbag.php and you call this with an include statment
PHP Code:
<?php
$cfraud_ip = getenv("REMOTE_ADDR");
$badips = dirname(__FILE__)."/dirtbag.dat";
$array = file( $badips );
$cfraud_ips = array();
foreach ( $array as $val )
$cfraud_ips[] = rtrim($val);
if(in_array($cfraud_ip, $cfraud_ips)) {
header("Location: http://www.yourwebsite.com/dirtbag.shtml");
exit();
}
?>
This is the data file or text file this serves as the array I call it dirtbag.dat I use rtrim to strip any spaces left in the file out look below no comma required just the ips. my foreach statment loops through the array to the end. If the Ips match then I kick them to the page or site I want to, and off the page they came to
dirtbag.dat file contents below
PHP Code:
41.204.224.7
41.204.224.25
41.205.188.27
58.4.97.173
58.120.155.246
58.147.0.228
59.77.17.245
59.95.0.201
60.190.79.18
61.9.62.6
61.178.18.96
I am sure you can follow the vars
This is where the file ends up becoming an array
PHP Code:
$array = file( $badips );
Below I compare the persons ip against the ips found in the array $cfraud_ips = array();
PHP Code:
if(in_array($cfraud_ip, $cfraud_ips))