Jump to content

[SOLVED] PHP Check info from .txt file


pkirsch

Recommended Posts

Hello,

I am making a PHP script that checks IP Addresses from a text file, and if an IP is listed, it will redirect the user.

Problem is; I don't know how to check the file (probably using fread or fgets but please help Me on this.) The IP's are separated by putting them each on a new line!

 

Thanks so much for Your Time,

pkirsch

 

:)

Link to comment
https://forums.phpfreaks.com/topic/49687-solved-php-check-info-from-txt-file/
Share on other sites

In this case would the .txt file be a "Blacklist" or a "Whitelist"?

How do I tell the "IP Checker" script that a new IP is on every new line; and to check them all!?

And actually I think i want to separate them with single quotation marks.

 

Example:

 

'192.168.1.1'

'144.64.22.5'

'00.66.00.5.4'

the black list / white list depends on you the comment in Trope's (sorry Thorpe saw your other comment) post says that that is where you put the code when the IP is found in the list

 

the PHP function file() takes in a file and splits it into an array by lines, if your IP addresses are all on new lines then each key of the array will hold a different one. the if statement then asks whether the supplied IP address is in the array.

 

 

Easiest to use file. <----- this word in thorpes posting is a link to the file() function its worth a read

 

if you seperate them with a single character, lets say a comma then you could use <a href="http://uk.php.net/manual/en/function.explode.php">explode()</a> also a link

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.