TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-03-2011, 10:32 PM   #1 (permalink)
The Contributor
 
Tim Dobson's Avatar
 
Join Date: Feb 2010
Posts: 69
Thanks: 16
Tim Dobson is on a distinguished road
Default 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($fhfilesize($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!
Tim Dobson is offline  
Reply With Quote
Old 03-03-2011, 10:48 PM   #2 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

I don't get where the problem is? I am guessing from your intro is in your second example where you are trying to read the file of ips.
I would use the file function if the ips are in every line of the file, instead of the fopen/fread/fclose combo
tony is offline  
Reply With Quote
The Following User Says Thank You to tony For This Useful Post:
Tim Dobson (03-04-2011)
Old 03-04-2011, 03:45 PM   #3 (permalink)
The Contributor
 
Tim Dobson's Avatar
 
Join Date: Feb 2010
Posts: 69
Thanks: 16
Tim Dobson is on a distinguished road
Default

ok so i changed it to

PHP Code:
$ban_ip_list file("E:\domains\s\sb0t.tentun.co.uk\user\htdocs\Admin\docs\bannedfull.txt"); 
but i still get nothing and it still does nothing so i really dont get it.


full script is

PHP Code:
$ban_ip_list file("E:\domains\s\sb0t.tentun.co.uk\user\htdocs\Admin\docs\bannedfull.txt");
$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);
    }
}
}
?> 
Tim Dobson is offline  
Reply With Quote
Old 03-04-2011, 03:48 PM   #4 (permalink)
The Contributor
 
Tim Dobson's Avatar
 
Join Date: Feb 2010
Posts: 69
Thanks: 16
Tim Dobson is on a distinguished road
Default

oh nevermind i had my text file wrong thanks for the advice on using file. much appriciated
Tim Dobson is offline  
Reply With Quote
Old 03-04-2011, 03:50 PM   #5 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

Great, I find file and file_get_contents more useful.
tony is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
includes and reading txt file Tim Dobson Absolute Beginners 2 07-08-2010 10:43 PM
Write Mysql results to a text file CΛSTΞX General 3 02-02-2010 05:27 AM
php/html form to echo text file contents Hustle Absolute Beginners 2 03-10-2009 07:14 AM
Read Text File in Reverse buildakicker General 9 11-26-2008 06:43 PM
Database export to text file... d4v1d Absolute Beginners 5 01-09-2008 04:30 PM


All times are GMT. The time now is 12:22 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design