如何使用 reCaptcha 从机器人中隐藏我网站上的 PDF 文件?
How to hide PDF file on my website from bots with reCaptcha?
我目前正在尝试在我的个人网站上共享 PDF 文档。
当这不是问题时,我需要对机器人隐藏它。
我尝试使用 google 的 Invisible reCAPTCHA,但遇到了一些问题。
网络爬虫可以搜索源代码,因此非活动按钮不起作用。
我是否需要一个特殊页面来检查 reCAPTCHA 是否已完成?也许有一种简单的方法可以在发现非人类时始终显示 link 但隐藏 link HREF 或形成 ACTION 属性(可能需要 PHP 帮助)?
<form id="resume" action="subpage_that_shows_my_pdf_file_link.html" method="POST">
<button class="g-recaptcha" data-sitekey="666" data-callback="onSubmit" type="submit">Submit</button>
</form>
实际上 google 文档对此没有帮助。
好的,我用 captcha-response 做到了。我的主要代码部分:
index.php
<form id="reCaptchaForm" action="file.php" method="POST">
<button class="g-recaptcha" data-sitekey="..." data-callback='onSubmit' >link</button>
</form>
file.php
if(isset($_POST['g-recaptcha-response'])) {
$secretKey = '...';
$response = $_POST['g-recaptcha-response'];
$remoteIp = $_SERVER['REMOTE_ADDR'];
$reCaptchaValidationUrl = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$response&remoteip=$remoteIp");
$result = json_decode($reCaptchaValidationUrl, TRUE);
if($result['success'] == 1) {
$userMessage = '<meta http-equiv="refresh" content="0;URL='file.pdf'" />';
}
只有在此特定会话中才会显示特殊页面代码 google 隐形验证码说 是的,看起来像普通用户 :)
我目前正在尝试在我的个人网站上共享 PDF 文档。
当这不是问题时,我需要对机器人隐藏它。
我尝试使用 google 的 Invisible reCAPTCHA,但遇到了一些问题。
网络爬虫可以搜索源代码,因此非活动按钮不起作用。
我是否需要一个特殊页面来检查 reCAPTCHA 是否已完成?也许有一种简单的方法可以在发现非人类时始终显示 link 但隐藏 link HREF 或形成 ACTION 属性(可能需要 PHP 帮助)?
<form id="resume" action="subpage_that_shows_my_pdf_file_link.html" method="POST">
<button class="g-recaptcha" data-sitekey="666" data-callback="onSubmit" type="submit">Submit</button>
</form>
实际上 google 文档对此没有帮助。
好的,我用 captcha-response 做到了。我的主要代码部分:
index.php
<form id="reCaptchaForm" action="file.php" method="POST">
<button class="g-recaptcha" data-sitekey="..." data-callback='onSubmit' >link</button>
</form>
file.php
if(isset($_POST['g-recaptcha-response'])) {
$secretKey = '...';
$response = $_POST['g-recaptcha-response'];
$remoteIp = $_SERVER['REMOTE_ADDR'];
$reCaptchaValidationUrl = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$response&remoteip=$remoteIp");
$result = json_decode($reCaptchaValidationUrl, TRUE);
if($result['success'] == 1) {
$userMessage = '<meta http-equiv="refresh" content="0;URL='file.pdf'" />';
}
只有在此特定会话中才会显示特殊页面代码 google 隐形验证码说 是的,看起来像普通用户 :)