How to limit php 1 load per hour?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
baoky
Forum Newbie
Posts: 12
Joined: Sat May 24, 2008 6:21 am

How to limit php 1 load per hour?

Post by baoky »

How to limit php 1 load per hour?

I want to make e.g my download.php can be only call once by a single ip once per hour.

if user call over 1 time within the hour , they will be Echo Error message that they only can call once with time left to the next call . is it possible?

can anyone provide me the code . thanks !
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: How to limit php 1 load per hour?

Post by onion2k »

baoky wrote:How to limit php 1 load per hour?

I want to make e.g my download.php can be only call once by a single ip once per hour.

if user call over 1 time within the hour , they will be Echo Error message that they only can call once with time left to the next call . is it possible?
Sure it's possible. Store a list of the IP addresses that have accessed the script in a database table with a timestamp. Whenever someone tries to download the file check the list ... if the IP isn't there then the user is allowed to download the file, which you send to them, and at the same time add their IP to the table with the current time. If the user's IP is already in the table then don't send them the file. Whenever anyone accesses the script delete any timestamps that are more than an hour old before checking if the current user is allowed though, otherwise if noone has accessed the download since that user tried then they would be blocked.

Eg

User loads the script
Delete all the IP addresses more than 1 hour old
Check for the user's IP
If it's not there send the file to the user
If it is there send the error message to the user
Add the user's IP to the database table
baoky wrote:can anyone provide me the code . thanks !
No. Noone here is running a free code writing service for you. If you want to pay someone then post in the Job Hunt folder.
Post Reply