Restrict script use (number of times per day) using php & mysql

If you are a programmer and want your script to be restricted to say 5 time use only per day, then here is the basic idea about how to do it in this post. Please let me know if you feel any difficulty or need any code example etc too.

We need to make a database table to store the data. Make a table in db having three columns / fields named:

  • username
  • number
  • date

Now come to the php side. Edit the code so that when ever the user uses the script on the site, it check in the field for number and checks if its >0 and <6 . Then it checks for the date, if the date is todays date, then it simply adds +1 for the number field, until it is <6, if it = 6, then it stops or returns your custom error code and terminates the process.

Now if the date is not todays date, then simply number = 1 and date = todays date for the current user.

Hope it helps. This logic can be implemented in any other programming language too, however i kept php and mysql in mind while writing this article.

Leave a Reply

Your email address will not be published.