Reputation: 368
I have a .txt file which contains about 100.000 IP's (Blacklisted), I want to check if the current user IP is present in that .txt file, if yes script execution should stop.
What would be the most efficient way to do this without using .htaccess.
Upvotes: 0
Views: 1247
Reputation: 4550
I think the way you are going to store the data will help you to lookup faster. Keeping the data into the sorted format and then try to do the binary search kind of thing help you to search the thing faster. I am just suggesting the theory part :)
Upvotes: 0
Reputation: 1090
$file = file_get_contents( "your_text_file.txt" );
if( preg_match( "/$ip/", $file ) ) {
// block
}
If you're going to block using preg_match you may want to add the newline to the search string and escape the period characters because otherwise they will match any single character ( however unlikely, this may block normal users ). Htaccess is much better suited for this or even a database query.
Upvotes: 1