How do I write and retrieve strings from a text file using PHP?
Okay I have a "bot trap" that writes offending IPs to a database table and then uses the table to decide to allow or deny requests to my site. Every now and then, however, a really bad bot will come along and take down my database server by making requests so fast that they exceed the number of connections I am allowed at any one point in time.
I could go to a dedicated database server but this costs $$$ I'd rather save. What I want to do is program a "safety switch" that writes the offending IP address to a new line in a text file along with the timestamp (e.g. 123.123.123.123 | 2007-07-18 01:10:02 EDT) if the database has recorded a certain number of requests for an offending IP address. Then before any database calls are made, my script would verify the IP address against the text file and deny the IP address in question access to my site.
So my question is, using PHP how do I write a string to a text file and then how do I query that text file (e.g. like a database table) to see if an IP address is listed in it?
Thanks