2014-06-20 25 views
0

我在我公司的網站上使用PHP reCAPTCHA。我基本上只是遵循這個教程https://developers.google.com/recaptcha/docs/php這是非常簡單的。無論如何,Chrome和Safari上的所有內容都可以正常顯示和提交,但在IE10和Firefox上,reCAPTCHA框不會顯示客戶端。我有點偏離教程,我沒有單獨的驗證頁面,但我仍然沒有看到這將如何影響在各種瀏覽器上顯示的圖像。有什麼建議麼?爲什麼我的PHP reCAPTCHA只能在Chrome和Safari上顯示?

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

Google Chrome喜歡自動更正錯誤的HTML語法。確保你的recaptcha_get_html()函數返回正確的HTML代碼。 recaptcha_get_html函數是什麼?

源代碼是否包含任何reCaptcha的東西,還是完全丟失?

你有一個網頁的例子,住在哪裏?

對不起,這被標記爲答案,我仍然無法評論帖子?

+0

下面是該頁面的鏈接:http://dept.ku.edu/~wstaff/question/quick_question.php我假設我只是在使用錯誤的HTML語法,只是拋棄它,謝謝爲了洞察。我基本上在上面發佈了該頁面的源代碼;我知道reCAPTCHA教程指出body標籤是必需的,或者它不會在某些瀏覽器上呈現,所以也許這是原因。 – Traug

+0

奇怪,但現在CAPTCHA圖像在所有四個Web瀏覽器上呈現。我在週末完全沒有變化...... – Traug

+0

如果其他人閱讀這篇文章,我認爲這個問題不在瀏覽器本身,但代碼被谷歌根據它收到的異常流量阻止。我在我的個人筆記本電腦上使用Chrome,Firefox,IE和Safari測試了我的網站,並且驗證碼顯示正常,而我一直在測試的正常工作計算機仍然不顯示在Chrome,IE和Firefox上(僅顯示在Safari仍然)。我想這就是爲什麼所有四個Web瀏覽器在一個週末之後都能正常工作的原因,但是在一兩天的測試後開始阻止訪問。 – Traug

相關問題