How To Disable Uploading Within a Time Limit
How can I keep a client from uploading more after having uploaded something within a time limi开发者_如何学编程t? Based on IP address.
Basing your disabling on the user's IP address is ineffective. In addition to what Kel said, the client also may have a dynamic IP, or be using Tor.
Really the only way would be to force the user to identify him/herself in some way. There are lots of options out there: Facebook, OpenID, Twitter, etc. You could create a user account system for your site, but that would be much more inconvenient for the user; using an infrastructure that's already in place would be better.
As for the more technical side of things, basically you'll keep a database table of users that have uploaded files, and a timestamp column that holds the time that they uploaded. You'll regularly traverse this table with a Cron job, and remove users that are older than a pre-defined threshold.
When a person attempts to upload, check if they're in the database. If they are, they can't upload; if they aren't, they're good to go.
You can retrieve IP address using $_SERVER['REMOTE_ADDR'] and $_SERVER['HTTP_X_FORWARDED_FOR'] variables, and store it somewhere together with request date (for example, in database). On each upload request you can check, whether (last upload time from this IP) - (current time) > period.
BTW, user is not always bound to single IP, and single IP can be used by many users. So, for example, this will restrict uploading from users, who are hidden behind the same NAT.
I guess there is no full proof way, and for any suggestion there's counter argument.
But then again, websites still allow uploading and live.
You can combine different methods of identifying an user:
Regular cookie
Flash cookie
IP address
All of these can be overcome, but not everyone even knows about flash cookies, and some people still change their IP by switching the modem on/off. Never underestimate people's lazyness / ignorance:)
精彩评论