Anti-Bot comment system - PHP
<blockquote>
  <h3>Update:</h3>
  
  <p>Question posted at <strong>CodeReview: <a href="http://codereview.stackexchange.com/questions/2362/anti-bot-comment-system">http://codereview.stackexchange.com/questions/2362/anti-bot-comment-system</a></strong></p>
</blockquote>

<p>With some advice from SO [see the details on my previous questions if you are interested] i developed the system, which i think is quite strong for bot to automatically post comment !<br>
I'm posting my code so you can view it and post some valuable comments !!<br>
Any kind of constructive suggestion is welcome :)  </p>

<p><code>index.php</code>  </p>

<pre><code>&lt;html&gt;
&lt;head&gt;
&lt;script type="text/javascript" src="jquery.js"&gt;&lt;/script&gt;
&lt;script&gt;
function main()
{
 var str=$("#key").load("getToken.php",function (responseText) {
                                                 $("#key").val(responseText);
                                               }
      );
 setTimeout("main()", 100000);
}
&lt;/script&gt;
&lt;/head&gt;
 &lt;body onload='main()'&gt;
 &lt;form name="f" action="poster.php" method="post"&gt;
  &lt;input type="text" name="text"/&gt;&lt;br&gt;
  &lt;input type="text" name="key" id="key" value=""/&gt;&lt;br&gt;
  &lt;input type="submit"&gt;
 &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p><code>getToken.php</code></p>

<pre><code>&lt;?php
 $key=date("Y-m-d H:i:s");
 $hash=sha1($key.'mySecretKey');
 echo $key.'#'.$hash;
?&gt;
</code></pre>

<p><code>poster.php</code></p>

<pre><code>&lt;?php
if (!isset($_POST['key']))
 exit;

$parts = explode('#',$_POST['key'],2);
$key = $parts[0];
$hash = $parts[1];

$date1 = $key;
$date2 = date("Y-m-d H:i:s");
$diff = abs(strtotime($date2) - strtotime($date1)); 
$years   = floor($diff / (365*60*60*24)); 
$months  = floor(($diff - $years * 365*60*60*24) / (30*60*60*24)); 
$days    = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
$hours   = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/ (60*60)); 
$minuts  = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/ 60); 
$seconds = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minuts*60)); 

if ($seconds &lt; 5)
 echo $seconds.' Too fast, must be a naughty bot &lt;br&gt;';
else if ($seconds&gt;5 &amp;&amp; $seconds &lt; 600)
 echo $seconds.' In time &lt;br&gt;';
else
 echo $seconds.' time out &lt;br&gt;';

if ($hash == (sha1($key.'sou')))
 echo $_POST['text'];
else
 echo 'You are a bot !';
?&gt;
</code></pre>
