繁体   English   中英

如何验证recaptcha?

[英]How do I validate recaptcha?

我的表单中显示了recaptcha,但是当有人点击提交时,我只会得到一个空白的白色屏幕。 现在,我已将有问题的 php 注释掉,该网站的工作原理可以在www.necowindtest.com的评论选项卡下看到。 这是单击提交按钮时运行的 php 例程: 注释部分之后的所有内容都有效。

        <?php
// define variables and set to empty
            $moniker = $commentdate = $comment = "";
//          
//set timezone to mountian
            date_default_timezone_set("America/Denver");
//
/*This starts the possibly problematic statements   
//
// files placed in root of server
            require_once "recapthchalib.php";
//
//exit for troubleshooting move this up if you didn't get a message or down if you did
            exit("MADE IT THIS FAR");
//              
//secret key
            $secret = "6LfUTwoaAAAAAGIDFC8FqCoZX0TOTzSKFyOKT57h";
//          
//empty response
            $response = null;
//          
//check secret key
            $reCaptcha = new ReCaptcha($secret);
//
//if submitted check response
            if ($_POST["g-recaptcha-response"]){
                $response = $reCaptcha->verifyResponse(
                    $_SERVER["REMOTE_ADDR"],
                    $_POST["g-recaptcha-response"]
                    );
            }
//
//display form or thank you for submission
                if ($response != null && $response->success) {
                    echo "Hi " . $_POST["moniker"] . " thanks for the submission";
                }
                else {
                    echo "Sorry captcha verification was unsuccessful";
                }
//
//This is the end of the problematic statements
//
*/                  
//load form fields into variables and check for extraneous characters           
            if ($_SERVER["REQUEST_METHOD"] == "POST") {
                $moniker = test_input($_POST["moniker"]);
                $comment = test_input($_POST["comment"]);
            }
//          
            function test_input($data) {
                $data = trim($data); //trim out spaces
                $data = stripslashes($data); //strip out slashes
                $data = htmlspecialchars($data);  //change special characters to entities
                return $data;
            }       
//                      
//write comment to end of comment file (commenttest.txt)
            $dateofcomm = date("m-d-Y");
            $dateofcomm = $dateofcomm . " ";
            $newline = "\n";
            $comment = $comment . " ";
            $moniker = str_replace(" ", "", $moniker);
            $newrecord = $dateofcomm . $comment . $moniker;
//
            $prevcomm = fopen("commenttest.txt", "r") or die ("Unable to open file");
                $allfiledcomments = file_get_contents("commenttest.txt");
                file_put_contents("commenttest.txt", $dateofcomm);
                file_put_contents("commenttest.txt", $comment, FILE_APPEND);
                file_put_contents("commenttest.txt", $moniker, FILE_APPEND);
                file_put_contents("commenttest.txt", $newline, FILE_APPEND);
                file_put_contents("commenttest.txt", $allfiledcomments, FILE_APPEND);
            fclose($prevcomm);
//
//display return link
                echo "<div class='container' style='text-align: center'><br>";
                    echo "<a href='comments.php'><h2>Return to site</h2><br>";
                echo "</div>";
//          
//read comments from file  (commenttest.txt)        
            $prevcomm = fopen("commenttest.txt", "r") or die ("Unable to open file");
            while (!feof($prevcomm)) {      
                $acomm = fgets($prevcomm);
                $acomm = chop($acomm);
                $commdate = substr($acomm, 0, 10);
                $bypos = strrpos($acomm, " ",);     //get position of last space before name
                $commenter = substr($acomm, $bypos,);       //name is from last space to end
                $bypos = $bypos - 10;
                $filedcomm = substr($acomm, 11, $bypos); //comment is from position 11, after the date, to last space left to right
//
//write formatted comment to screen
                echo "<div container style='font-size: 25px; border: solid red; border-radius: 20px;'><br>";
                    echo "<div container style='padding-left: 25px;'>"; 
                        echo $commdate; 
                    echo "</div>";  
                    echo "<div container style='padding-left: 50px; width: 225px; display: inline-block;'>";
                        echo "<h2><strong>COMMENT: </strong></h2>";
                    echo "</div><br>";
                    echo "<div container style='padding-left: 75px; width: 600px; display: inline-block;'>";
                        echo $filedcomm;
                    echo "</div><br>";
                    echo "<div container style='padding-left: 50px; width: 100px; display: inline-block;'>";
                        echo "<h2><strong>BY: </strong></h2>";
                    echo "</div>";
                    echo "<div container style='padding-left: 1px; width: 500px; display: inline-block;'>";
                        echo $commenter;
                    echo "</div>";          
                echo "</div><br>";              
            }
            fclose($prevcomm);  
        ?>

谢谢阿尔瓦罗,花了一段时间,但我想出了如何让 bluehost 显示 php 错误。 现在我越来越近了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM