php - PHP | 谷歌验证码文件
问题描述
对,我真的开始对这件事失去兴趣了。为什么,每当我使用 Google Publish 的代码来启用他们的 Google Captcha 文档时,我只会在网页上显示原始代码,尽管从 HTML 转换为 PHP 文档并遵循所有内容?
这是一个 HTML 文档,文件已更改为php
扩展名,文档中仍有 HTML 代码,但php
代码在body
标签中。
<!doctype html>
<html>
<head>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
</head>
<body>
<!---HTML CODE HERE--->
<?php
// Checks if form has been submitted
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
function post_captcha($user_response) {
$fields_string = '';
$fields = array(
'secret' => '_______________PRIVATE_KEY_______________',
'response' => $user_response
);
foreach($fields as $key=>$value)
$fields_string .= $key . '=' . $value . '&';
$fields_string = rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result, true);
}
// Call the function post_captcha
$res = post_captcha($_POST['g-recaptcha-response']);
if (!$res['success']) {
// What happens when the CAPTCHA wasn't checked
echo '<p>Please go back and make sure you check the security CAPTCHA box.</p><br>';
} else {
// If CAPTCHA is successfully completed...
// Paste mail function or whatever else you want to happen here!
echo '<br><p>CAPTCHA was completed successfully!</p><br>';
}
} else { ?>
<!-- FORM GOES HERE -->
<form method="POST" action="/scripts/mail_html.php" enctype="multipart/form-data">
<input type="email" name="email" required placeholder="Enter your email"/>
<div class="g-recaptcha" data-sitekey="_______________PUBLIC_KEY_______________"></div><br/><br/>
<p>By subscribing you agree to receive marketing communications from xxxxxl. You can unsubscribe anytime using the link in the footer of any of our emails. See our <a style="text-decoration: underline;" class="inline_link__new_window" target="_new" href="xxxx">Privacy Policy</a></p><br/>
<input type="submit" value="Subscribe"/>
</form>
<?php
} ?>
</body>
</html>
如您所见,您可以清楚地看到编码,而不仅仅是表单。
为什么?
解决方案
推荐阅读
- javascript - 页面加载后我的第一个 api 请求总是失败
- php - Instagram 追随者计数脚本让我很难过。(PHP)
- javascript - 通过ajax调用传递参数 - ajax url
- batch-file - 杀死、清理并重新启动 Firefox
- python - 从字典中获取所有值(包括字典中字典的值)
- python - 使用 scapy 在 IP 示例中制作 IP
- python - 如何在 Django 中重复多对多关系?
- python - 大家好,有人知道如何读取用户在 discord.py 中上传的文件吗
- c++ - QListView 不显示标题
- css - 如何在 flex 容器中对齐两个居中 div 的顶部?