Why does my PHP reCAPTCHA only display on Chrome a

2019-08-27 01:35发布

I'm using the PHP reCAPTCHA on my company's website. I basically just followed this tutorial https://developers.google.com/recaptcha/docs/php which is pretty straightforward. Anyway, everything displays and submits fine on Chrome and Safari, but on IE10 and Firefox the reCAPTCHA box simply doesn't show up client-side. I somewhat diverge from the tutorial in the way that I don't have a separate verification page, but I still don't see how this would affect the image displaying on various browsers. Any suggestions?

<?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
}
?>

1条回答
Deceive 欺骗
2楼-- · 2019-08-27 02:25

Google Chrome likes to auto correct bad HTML syntax. Make sure your recaptcha_get_html() function returns proper HTML code. What is the recaptcha_get_html function?

Does the source code contain any reCaptcha stuff, or is it entirely missing?

Do you have an example of the web page somewhere live?

Sorry this is marked as an answer, I can not comment on posts still?

查看更多
登录 后发表回答