I've got a page which contains a form: when page is requested, a session is stored:
$_SESSION['ok']=date("His");
Plus, the form contains this hidden field:
<input type="text" name="email-confirm" id="email-confirm" style="display:none;" placeholder="Do not fill this field">
When user sends the form, the following PHP code is launched to check if they're not a bot:
session_start();
if(!isset($_SESSION['ok'])){die('Error: you have to enable cookies in order to make everything work fine.');}
$fast = date("His") -4;
if($fast < $_SESSION['ok']){$_SESSION['banned']=1;
die('Woah, that was fast! Would you mind doing a little captcha verification? Refresh the page to continue.');}
if(!empty($_POST['email-confirm'])){$_SESSION['banned']=1;
die('You\'ve been temporarily banned.<br>
Refresh the page to lift the ban with a captcha verification.');
}
If session 'banned' is set and user tries to visit any page on the site, they're asked to complete a captcha challenge which relies on google recaptcha.
Is this method to block bots reliable?
I don't like very much the idea to ask every user to complete a captcha verification, because I feel like it would be annoying to do that every time, but if it's the only method to be really safe, then I'd adopt it.