03-03-2011, 10:32 PM
|
#1 (permalink)
|
|
The Contributor
Join Date: Feb 2010
Posts: 69
Thanks: 16
|
reading text file for array
Ok so i have been fighting with this script for a bit now and finaly give up, looking at examples just got me slightly confused!
so the plan is to read the array from the text file rather than have it in the php script itself. so the original script is
PHP Code:
<?php
$ban_ip_list = array('123.2.143.239', '456.222.127.140', '92.235.8.232', );
$ban_ip_range = array('987.239.*', '888.2.*', '765.101.*');
/* Visitor's IP Address */
$user_ip = $_SERVER['REMOTE_ADDR'];
/* Message to output if the IP is in the ban list */
$msg = 'You do not have permission to access this page. If you think this is incorrect please e-mail tim@tentun.co.uk with your IP address. <a href="www.showmyip.com">www.showmyip.com</a>';
/* Message to output if the IP is in the ban list */
if(in_array($user_ip, $ban_ip_list))
{
exit($msg);
}
/* Check if the Visitor's IP is in our range's list */
if(!empty($ban_ip_range))
{
foreach($ban_ip_range as $range)
{
$range = str_replace('*','(.*)', $range);
if(preg_match('/'.$range.'/', $user_ip))
{
exit($msg);
}
}
}
?>
and what i attempted is:
PHP Code:
<?php
$myFile = "E:\domains\s\sb0t.tentun.co.uk\user\htdocs\Admin\docs\bannedfull.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
$ban_ip_list = array($theData);
$ban_ip_range = array('68.239.*', '188.2.*', '208.101.*');
/* Visitor's IP Address */
$user_ip = $_SERVER['REMOTE_ADDR'];
/* Message to output if the IP is in the ban list */
$msg = 'You do not have permission to access this page. If you think this is incorrect please e-mail tim@tentun.co.uk with your IP address. <a href="www.showmyip.com">www.showmyip.com</a>';
/* Message to output if the IP is in the ban list */
if(in_array($user_ip, $ban_ip_list))
{
exit($msg);
}
/* Check if the Visitor's IP is in our range's list */
if(!empty($ban_ip_range))
{
foreach($ban_ip_range as $range)
{
$range = str_replace('*','(.*)', $range);
if(preg_match('/'.$range.'/', $user_ip))
{
exit($msg);
}
}
}
?>
So could someone please fix this for me or tell me where i gone wrong? would be much appriciated thanks!
|
|
|
|