pkirsch Posted May 2, 2007 Share Posted May 2, 2007 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 Quote Link to comment Share on other sites More sharing options...
trq Posted May 2, 2007 Share Posted May 2, 2007 Easiest to use file. <?php $uip = '192.168.10.2'; $ips = file('textfileholdingips.txt'); if (in_array($uip,$ips)) { // ip found in file. } ?> Quote Link to comment Share on other sites More sharing options...
pkirsch Posted May 2, 2007 Author Share Posted May 2, 2007 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' Quote Link to comment Share on other sites More sharing options...
paul2463 Posted May 2, 2007 Share Posted May 2, 2007 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 Quote Link to comment Share on other sites More sharing options...
pkirsch Posted May 2, 2007 Author Share Posted May 2, 2007 Thanks A Lot for Your Time thorpe and paul2463, You have helped Me a lot! Have a great day, pkirsch Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.