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
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'

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.