Question license issue - call a function 3 times a day only

jamesvick

Active member
Joined
Jul 19, 2010
Messages
34
Programming Experience
1-3
hello, iam making an application which performs some string operations on a text in a richtextbox in the following way:

the user writes some text in a richtextbox and then clicks a button. The text is then send to a PHP page for operation and the result is then stored in another richtextbox. The php part cannot be removed and is important.

What i want is the license to allow x number of uses per day. So let's say that the person is allowed to use the function 3 times. This has to be done on the application itself. I also want to be able to detect any date/time change to prevent overuse. I thought to declare a variable and store it on HDD. But then it raises other problems.

Iam asking for a general idea as to how should i proceed?

AGAIN : Every day the person can use the click button for 3 times. This count should be reset every 24 hrs. The software won't run 24 hrs. So next time it launches it should update the count.
 
Wouldn't it make more sense to employ the security with PHP? For example, require the application to send a username & password along with the request so your PHP script can log in a database, how many times that user has accessed the script. If it's more than three, access denied.

That way you don't have to worry about people tampering with dates, files or cracking your application.
 
Yeah that is the problem. Iam no PHP dev and the basic function has been made in like 2 weeks. And believe me it's a simple task of some string manipulation. So that is why iam focusing on desktop tool. Anyways thanks for the answer.

If you have any knowledge can you tell me how i can reset the number of calls every 24 hrs? Any remotely related article you can point me to?

I can go with database and iam thinking the reset has something to do with cron jobs. Any idea anyone could give?

Help appreciated. :)
 
I can go with database and iam thinking the reset has something to do with cron jobs

You probably wouldn't need that. You could probably check the number of counts while the PHP script is running. In pseudocode:

VB.NET:
Script execution start
  Get number of executions related to the user (assume user has logged in)
  If number of executions is greater than three
    Get the time and date of the last access
    Get the current time
    If the last access was less than 24 hours ago, deny the request, end the script.
    If the last access was MORE than 24 hours ago, set the count to 0 and continue
  Process the rest of the script
  Return results to user
Script execution stop

That saves you have to mess around with CRON scripts and such, you can just do a quick check prior to actually doing the heavy lifting.

I'm not sure how ofay you are with databases, but SQL Tutorial is a good place to learn SQL and PHP Tutorial is good for learning more about PHP

Hope this helps!

(Oh, and http://php.net/manual/en/function.strtotime.php is a great PHP function for working with times. Type in strtotime("-24 hours") and it'll give you the Unix timestamp of 24 hours ago ;))
 
Back
Top