栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用AJAX的ReCaptcha 2.0

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用AJAX的ReCaptcha 2.0

好的,这很愚蠢。

我做错了几件事:

  • 在PHP文件中,所有字符串都用单引号引起来,这引起了问题。
  • 在整个测试过程中,我在PHP文件中添加了多个打印内容,因此该文件
    if (status == "ok")
    永远无法正常工作。我确实收到了电子邮件,但没有得到任何确认,现在我明白了为什么。
  • 当我想要检查遗漏的PHP文件时,我只是转到URL中的地址,并始终出现错误。即使邮件已发送。现在,我知道这不是检查日志的正确方法。

感谢@Samurai帮助我弄清楚了事情。


最终的PHP代码:

<?php    // assemble the message from the POST fields    // getting the captcha    $captcha = "";    if (isset($_POST["g-recaptcha-response"]))        $captcha = $_POST["g-recaptcha-response"];    if (!$captcha)        echo "not ok";    // handling the captcha and checking if it's ok    $secret = "MY_SECRET";    $response = json_depre(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secret."&response=".$captcha."&remoteip=".$_SERVER["REMOTE_ADDR"]), true);    // if the captcha is cleared with google, send the mail and echo ok.    if ($response["success"] != false) {        // send the actual mail        @mail($email_to, $subject, $finalMsg);        // the echo goes back to the ajax, so the user can know if everything is ok        echo "ok";    } else {        echo "not ok";    }?>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/399751.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号