HiveBrain v1.2.0
Get Started
← Back to all entries
patternphpMinor

Anti-Bot comment system

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
commentantisystembot

Problem

With some advice from SO, I developed this system, which I think is quite strong for bots to automatically post comments.

index.php


function main()
{
 var str=$("#key").load("getToken.php",function (responseText) {
                                                 $("#key").val(responseText);
                                               }
      );
 setTimeout("main()", 100000);
}

 
 
  
  
  
 


getToken.php



poster.php

';
else if ($seconds>5 && $seconds ';
else
 echo $seconds.' time out ';

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

Solution

-
3656060*24 should be a constant.

-
You should really improve your variable naming.

$date2 = date("Y-m-d H:i:s");


-
date2? Does that say anything? currentTime is more like it. Always describe what variables contain, not what they are.

-
Isn't $diff already the number of seconds?

-
Most part of the date/time checking could be rewritten to:

$seconds = time() - strtotime($key);

Code Snippets

$date2 = date("Y-m-d H:i:s");
$seconds = time() - strtotime($key);

Context

StackExchange Code Review Q#2362, answer score: 6

Revisions (0)

No revisions yet.