I need some ideas as to how to restrict the use of a complex script I have developed. It uses significant server resources, but I want to make it public, so I think the best way to go is to allow each IP to only run the script once every 10 minutes. I happy to do the work and write the code, but I'm a bit lost as to what I should do. If someone could give me maybe a outline of the most efficent way to implement the above system, I'd much appreciate it. So, in a nutshell, the script has to check if this IP has used it in the last ten minutes (I assume by saving records of visits somehow). If it has, it returns an error message. If you have some ideas, i'd be happy to PM you the site and access details. Thanks
You could store the IP in a database along with the exact time whenever the script is run. Then if the script is run again you check to see if there is a matching IP with a timestamp in the last 10 minutes.
That's a practical suggestion, as I have access to MySQL databases. However, I am not a hugely advanced php programmer (intermediate-ish), and it would be really helpful if someone could lay out the system in some kind of process chart, such as: Use XXX function to get time of script running Use XXX function to get user IP Use XXX function to write to database Use XXX check to see if the timestamp matches within last ten minutes Use XXX function to delete all entries from over an hour ago (would be useful, to stop database getting clogged) I just need some kind of step-by-step guide, but I am happy to do the actual programming Thanks for your help
What you're trying to do is quite far from advanced. Have you tried searching php.net? I'll help you a bit, but searching php.net for yourself really is faster For the time, I suggest using the UNIX timestamp. This is the time passed in seconds since the unix epoch. Use time(); To get the user ip, use this variable: $_SERVER['REMOTE_ADDR']; Now go and find out for yourself how to connect to the database . After that, see if there is a record by this ip, and, if so, if it is less than 10 minutes old (600 seconds). If this is the case, present your error message. Else, store the ip with timestamp and run the script If you've done this it shouldn't be hard to write a function yourself which deletes al entries older than an hour or so. Good luck!