Right, here's my code that limits the form submit rate. When the form is submitted it takes the timestamp and IP address, and then on page load this I have a SQL statement that takes the users IP, counts how many times it appears in the database in the past hour, and if it is 2 then the post box isn't displayed, else, it is, the problem is that it doesn't quite work, it just keeps showing the post box no matter what. Here's the code:
<?php
$IP = $_SERVER['REMOTE_ADDR'];
$sql = "select count(*) from mysql_table where ip='$IP' and timestamp > (DATE_ADD(now(), INTERVAL -1 HOUR))";
$result = mysql_query($sql) or print mysql_error();
if ($result['count(*)'] == 2) {
die('You are out of posts this hour.');
}
else {
?>
<font style="position:relative; margin: 0 auto; top:15px; color:#fff; font-size:16px; font-family:Arial;">Note, once you have posted, it <b>CANNOT</b> be removed.</font>
<div id="postbox">
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<textarea id="postbox" name="postbox"></textarea><br />
<input type="checkbox" name="allowcommenting" value="1" id="commenting" CHECKED ><font style="margin-right:45px; font-family:Arial; font-size:18px; color:#fff; position:relative; top:15px;">Allow commenting?</font>
<?php
require_once 'math-security.php';
$math = new BasicMathSecurity( 'math' );
echo $math->getField();
?>
<input type="submit" name="submit" id="submit" value="Share" value="This cannot be undone." />
</form>
</div>
<?php
}
?>
$IPbefore putting it into the database, even though it's highly unlikelyREMOTE_ADDRcan be forged$result['count(*)']??What's this? Also, are you sure you want to usedie()?