程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长


+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

PHP reCaptcha 未在网站上显示

发布于2022-05-23 22:42     阅读(828)     评论(0)     点赞(27)     收藏(0)


我正在尝试让 reCaptcha 为我的表单工作。无需 reCaptcha,表单本身就可以完美运行。以下是我的 .html 和 .php 文件中的相关代码。

问题是 reCAPTCHA 小部件根本没有显示在页面上。我可以让提交按钮工作,但当然它总是因为缺少小部件而失败。

sign_up.html

<div id="form">
    <script type="text/javascript">
        var RecaptchaOptions = {
        theme : 'white'
    };
    </script>
    <form class="pure-form" action="myprocessingscript.php" method="post">        
        <fieldset class="pure-group">
            <input name="field1" type="text" class="pure-input-1-2" placeholder="Name">
            <input name="field2" type="text" class="pure-input-1-2" placeholder="Username">
            <input name="field3" type="email" class="pure-input-1-2" placeholder="Email">
        </fieldset>
        <?php
            require_once('recaptchalib.php');
            $publickey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(censored)"; 
            echo recaptcha_get_html($publickey);
        ?>
        <button name="submit" type="submit" class="pure-button pure-input-1-2 pure-button-primary">Skicka</button>      
    </form>
</div>

我的处理脚本.php

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

  if (!$resp->is_valid) {
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
         "(reCAPTCHA said: " . $resp->error . ")");
  } else {
    if(isset($_POST['field1']) && isset($_POST['field2']) && isset($_POST['field3'])) {
    $data = $_POST['field1'] . '-' . $_POST['field2'] . '-' . $_POST['field3'] . "\n";
    $ret = file_put_contents('submissions.txt', $data, FILE_APPEND | LOCK_EX);
    if($ret === false) {
        die('There was an error writing this file');
    }
    else {
        echo "$ret bytes written to file";
    }
}
else {
   die('no post data to process');
}
  }

?>

谢谢您的帮助!


解决方案


1.将您的sign_up.html页面另存为sign_up.php 并删除代码,首先使其无需自定义即可工作。2.您是否将文件上传recaptchalib.php到您的根目录。

   <script type="text/javascript">
            var RecaptchaOptions = {
            theme : 'white'
        };
        </script>



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:http://www.qianduanheidong.com/blog/article/360632/5b4cf607d2ca8295ec02/

来源:前端黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

27 0
收藏该文
已收藏

评论内容:(最多支持255个字符)