【问题标题】:Why does my PHP reCAPTCHA only display on Chrome and Safari?为什么我的 PHP reCAPTCHA 只显示在 Chrome 和 Safari 上?
【发布时间】:2022-05-09 22:57:56
【问题描述】:

我在我公司的网站上使用 PHP reCAPTCHA。我基本上只是按照这个教程https://developers.google.com/recaptcha/docs/php 这很简单。无论如何,一切在 Chrome 和 Safari 上都可以正常显示和提交,但在 IE10 和 Firefox 上,reCAPTCHA 框根本不会出现在客户端。我与教程有些不同,因为我没有单独的验证页面,但我仍然看不出这会如何影响各种浏览器上显示的图像。有什么建议吗?

<?php
    $page = "visit";
    include 'layout/topnav.php';  
?> 

<script language="JavaScript">
function formValidate() {
    if (document.data.Comments.value == "") { alert("Please include a quick question"); return false; }
    else if (document.data.Email.value == "") { alert("Please include your email."); return false; }
    else return true;
}
</script>

<?php
$Added = False;
if (isset($_POST['submit1'])){

  require_once('recaptchalib.php');
  $privatekey = "xxxxx";
  $resp = recaptcha_check_answer ($privatekey,
                            $_SERVER["REMOTE_ADDR"],
                            $_POST["recaptcha_challenge_field"],
                            $_POST["recaptcha_response_field"]);

  if (!$resp->is_valid) {
   // What happens when the CAPTCHA was entered incorrectly

    echo "Your CAPTCHA response was not accepted. Please try again. See the Help button to the right of the entry field to learn more.";
    $Email=$_POST['Email'];
    $Comments=$_POST['Comments'];
    $Added = False;
  } 

  else {
    // Your code here to handle a successful verification

    /* Add to Database */

    $Email = '';
    $Comments = '';
    $Added = True;
   }

  }

  if(!$Added)
  {
  ?>


<html>
<head>
<body> <!-- the body tag is required or the CAPTCHA may not show on some browsers -->
<form method="post" action="quick_question.php" name="data" onsubmit="return formValidate()">     
<b>Your Quick Question:<font color="red">*</font></b><br />
        <textarea wrap="hard" name="Comments" rows="5" cols="55" id="question" class="inputBox" ><? echo $Comments?></textarea>

        <table cellpadding="0">
            <tr>
                <td width="40%" valign="top"><b>Your E-mail:<font color="red">*</font></b></td>
                </tr>
                <tr>
                <td><input type="text" name="Email" size="10" id="email" class="inputBox" value="<? echo $Email?>"/></td>
            </tr>

        <tr><td>
        <b>CAPTCHA Verification:</b><font color="red">*</font>
        </td></tr>

        <tr><td>
        <?php
            require_once('recaptchalib.php');
            $publickey = "yyyy"; // you got this from the signup page
            echo recaptcha_get_html($publickey);
        ?>
        </td></tr>

        <tr><td id="submit">
        <input type="submit" name="submit1" />
        </td></tr>

        </table>
    </form>

</body>
</html>
<?php
}
?>

【问题讨论】:

    标签: php html cross-browser recaptcha


    【解决方案1】:

    Google Chrome 喜欢自动纠正错误的 HTML 语法。确保您的 recaptcha_get_html() 函数返回正确的 HTML 代码。 recaptcha_get_html 函数是什么?

    源代码是否包含任何 reCaptcha 内容,还是完全缺失?

    你有现场网页的例子吗?

    抱歉,这已标记为答案,我还不能评论帖子吗?

    【讨论】:

    • 这里是页面的链接:dept.ku.edu/~wstaff/question/quick_question.php 我假设我只是在某些时候使用了糟糕的 HTML 语法,这只是把它扔掉了,感谢您的洞察力。我基本上在上面发布了页面的来源;我知道 reCAPTCHA 教程指出 body 标签是必要的,否则它不会在某些浏览器上呈现,所以也许这就是原因。
    • 奇怪,但现在验证码图像正在所有四个 Web 浏览器上呈现。周末我完全没有做任何改变......
    • 如果其他人阅读了这篇文章,我认为问题不在于浏览器本身,而在于谷歌基于接收到的异常流量而阻止了代码。我在我的个人笔记本电脑上使用 Chrome、Firefox、IE 和 Safari 测试了我的网站,验证码显示正常,而我一直在测试的正常工作计算机仍然无法在 Chrome、IE 和 Firefox 上显示(仅显示在Safari 仍然)。我想这就是为什么所有四个网络浏览器在一个周末之后都表现良好,但在一两天的测试后开始阻止访问。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-01
    • 2011-02-15
    • 1970-01-01
    • 2014-08-30
    • 2019-06-02
    • 2011-02-18
    相关资源
    最近更新 更多