PHP style Anti-Spam
Author
Discussion

cronk-flakes

Original Poster:

3,480 posts

283 months

Tuesday 30th March 2010
quotequote all
One for the real tech-heads...

I have a PHP site, that allows users to comment, edit, post new items and a lot of other stuff.

The one thing that I can't seem to find a solution for, is anti-spam.

I use the obvious 'CAPTCHA' for signup and emailing etc, but lets say we perform an action such as commenting or a new forum post... Once the user has submitted their form for POST, the back end takes it an enters it. Now, if I hit refresh, it processes the POST request again.

Currently, I use a timestamp + 30, to make the users wait 30 seconds before being allowed to submit successfully, but I would like to be a bit more clever than that. I've looked around and can't seem to find any solutions.

One though, was to take timestamp - 100, and then plus 30 everytime they post, (so that multiple posts in a short time frame will cause the timestamp to be greater than time()) but there is a flaw, if someone posts once, then waits an hour, this timestamp will be timestamp-3600 or the like.

I've you've understood any of the above, your thoughts would be welcomed! thumbup

American iv

468 posts

226 months

Wednesday 31st March 2010
quotequote all
if all you're wanting to achieve is avoid someone pressing refresh, you could:

  • Post the reply via AJAX where available. Use JavaScript to disable submit buttons etc.
  • Use an redirect page (e.g. the form action is on a seperate page to the "thank you").
  • Why not include the time within the form submission (easily done with Javascript onsubmit) - if the two are within a certain tollerance then fine...
Just remember, if you're using a JavaScript solution to make sure its unobtrusive and works fine for users without JavaScript turned on...

Xenocide

4,286 posts

238 months

Wednesday 31st March 2010
quotequote all
Store the request with the post data's timestamp in a session variable?

cronk-flakes

Original Poster:

3,480 posts

283 months

Wednesday 31st March 2010
quotequote all
Thats a very simple way of approaching it! I hadn't thought of it like that.

Cheers fellas! thumbup