fatboyuk Posted December 28, 2008 Share Posted December 28, 2008 Hey guys. I have a text file that has a list of IP addresses: 1.2.3.4 5.6.7.8 2.4.6.8 3.5.7.9 etc etc Now, I need to search this file using PHP to see if an IP address is in that list. I have a bit of code: $file = file_get_contents($iprecord); if(!strpos($file, $visitorip)) { # REDIRECT TO PAGE 1 } else { # REDIRECT TO PAGE 2 } Now for some reason, even though the IP address is in the list, the visitor is always getting redirected to PAGE 1. I am guessing there is a format problem but cannot figure it out so any help appreciated!! Link to comment Share on other sites More sharing options...
0 fatboyuk Posted December 28, 2008 Author Share Posted December 28, 2008 Its okay - found the problem damned whitespace!!! Link to comment Share on other sites More sharing options...
0 Flanamacca Posted January 3, 2009 Share Posted January 3, 2009 Its okay - found the problem damned whitespace!!! Just a rule of thumb - instead of just going through absolute gluts of text in a single bound - its usually better practice to break up the text into small chunks. This also makes it easier to process on a per line (or in your case ip) basis and allow for phps trim operations to be applied and ensure that whitespaces are no longer an issue. Link to comment Share on other sites More sharing options...
0 fatboyuk Posted January 3, 2009 Author Share Posted January 3, 2009 Just a rule of thumb - instead of just going through absolute gluts of text in a single bound - its usually better practice to break up the text into small chunks. This also makes it easier to process on a per line (or in your case ip) basis and allow for phps trim operations to be applied and ensure that whitespaces are no longer an issue. I did go that way in the end - one text file per day and one IP per line, those files are small enough to play with then. I also have learned the benefits of trim!!! Link to comment Share on other sites More sharing options...
Question
fatboyuk
Hey guys.
I have a text file that has a list of IP addresses:
Now, I need to search this file using PHP to see if an IP address is in that list.
I have a bit of code:
$file = file_get_contents($iprecord); if(!strpos($file, $visitorip)) { # REDIRECT TO PAGE 1 } else { # REDIRECT TO PAGE 2 }Now for some reason, even though the IP address is in the list, the visitor is always getting redirected to PAGE 1.
I am guessing there is a format problem but cannot figure it out so any help appreciated!!
Link to comment
Share on other sites
3 answers to this question
Recommended Posts