Anti-Bot comment system - PHP -


update:

question posted @ codereview: https://codereview.stackexchange.com/questions/2362/anti-bot-comment-system

with advice [see details on previous questions if interested] developed system, think quite strong bot automatically post comment !
i'm posting code can view , post valuable comments !!
kind of constructive suggestion welcome :)

index.php

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

gettoken.php

<?php  $key=date("y-m-d h:i:s");  $hash=sha1($key.'mysecretkey');  echo $key.'#'.$hash; ?> 

poster.php

<?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 < 5)  echo $seconds.' fast, must naughty bot <br>'; else if ($seconds>5 && $seconds < 600)  echo $seconds.' in time <br>'; else  echo $seconds.' time out <br>';  if ($hash == (sha1($key.'sou')))  echo $_post['text']; else  echo 'you bot !'; ?> 

it's being closed since not code review or improvement. there se site that.

as code: 365*60*60*24 should constant.

you should improve variable naming.

$date2 = date("y-m-d h:i:s"); 

date2? anything? currenttime more it. always describe variables contain, not are.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -