Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this questionUpdate:
Question posted at CodeReview: https://codereview.stackexchange.com/questions/2362/anti-bot-comment-system
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 !
I'm posting my code so you can view it and post some valuable comments !! Any kind of constructive suggestion is 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 onl开发者_如何学JAVAoad='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.' Too fast, must be a 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 are a bot !';
?>
It's being closed since SO is not about code review or improvement. There is another SE site for that.
As for the code: 365*60*60*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.
精彩评论