Using a randomly generated token for flood control.
Posted
by James P
on Stack Overflow
See other posts from Stack Overflow
or by James P
Published on 2010-06-13T14:24:36Z
Indexed on
2010/06/13
14:32 UTC
Read the original article
Hit count: 281
Basic setup of my site is: user enters a message on the homepage, hits enter and the message is sent though a AJAX request to a file called like.php
where it echo's a link that gets sent back to the user.
I have made the input disable when the user presses enter, but there's nothing stopping the user from just constantly flooding like.php
with POST request and filling up my database.
Someone here on SO told me to use a token system but didn't mention how. I've seen this being done before and from what I know it is effective.
The only problem I have is how will like.php
know it's a valid token? My code is this at the moment:
$token = md5(rand(0, 9999) * 1000000);
and the markup:
<input type="hidden" name="token" value="<?php echo $token ?>" />
Which will send the token to like.php
through POST. But how will like.php
know that this is a valid token? Should I instead token something that's linked to the user? Like their IP address? Or perhaps token the current minute and check that it's the same minute in like.php
...
Any help on this amtter would be greatly appreciated, thanks. :)
© Stack Overflow or respective owner