PDA

View Full Version : Time Limit



Drugs
10-08-2006, 02:41 PM
<?php

$name = $_POST['name'];
$message = $_POST['message'];
$IP = $_SERVER['REMOTE_ADDR'];

if(empty($name) OR empty($message))
{
echo "

<script language='javascript'>

alert('You forgot to fill in one or more form fields...');

</script>
";

}
else
{

$name = htmlspecialchars($name);
$message = htmlspecialchars($message);
$shout = ("<font size=\"1\" face=\"Verdana\">
<b>$name</b>; $message<br><br>");

$read = fopen("textfiles/messages.txt", "r");
$contents = fread($read, filesize('textfiles/messages.txt'));
fclose($read);

$write = fopen("textfiles/messages.txt", "w");
fwrite($write, "$shout $contents");
fclose($write);

}
print "<meta http-equiv=\"refresh\" content=\"0;shoutbox.php\">";

?>


How do i make it so each unique user can only post once every 15 seconds?

Correctable (Forum Moderator) - Thread moved to Coding. Please post in the correct section.

Per
10-08-2006, 02:45 PM
Dude this is like your 40th thread on your shoutbox, dude just make ONE thread called Drug needs help with shoutbox ;D
Then update there.

Drugs
10-08-2006, 02:47 PM
Nah, lmao.

Per
10-08-2006, 02:48 PM
Lmao :P
But most of them are like Shoutbox or Help!11one :P
So yeah *bumpage*

ClubTime
10-08-2006, 09:16 PM
Is that the admin addtag or the normal one?

nets
11-08-2006, 04:20 PM
An easy option would be to set a cookie which expires 15 seconds after being set, and each time the script is ran check if the cookie is set (and if it is, exit the script.) However, if someone were to clear their cookies or not have cookies enabled the script wont work.


if(isset($_COOKIE[postTime])) {

print "<script type='text/JavaScript'>\n";
printf(" alert('You cannot post more than once in 15 seconds, please wait %s seconds before

posting again.');\n",
(15-(time()-$_COOKIE[postTime])));
print "</script>";

exit();

}

setcookie('postTime', time(), time()+15);
*I haven't tested that script*

I could create a script which uses MySQL, where it stops an IP address accessing the post page more than once in 15 seconds (if you feel this isn't enough protection.)

Want to hide these adverts? Register an account for free!