donglu9134 2013-12-27 12:23
浏览 157
已采纳

致命错误:调用未定义的函数recaptcha_check_answer()

Hi I am attempting to impliment Recaptcha into my php file to secure a page that allows users to add comments. but I am getting this fatal error: Fatal error: Call to undefined function recaptcha_check_answer() in /home/fh11alb/public_html/home.php on line 30

Does anybody know what I might be doing wrong?

<?php
session_start();
if (!isset($_SESSION['logged'])){
$_SESSION = array();
$_SESSION = destroy();
require_once('recaptcha/recaptchalib.php'); 
header('location: home_start.php'); //your login form
require_once("functions.php");
include_once("home_start.php");
}

$db_hostname = 'xxxx';
$db_database = 'xxxx';  
$db_username = 'xxxx'; 
$db_password = 'xxxx'; 
$db_status = 'not initialised';
$str_result = ' ';
$str_options = ' ';
$db_server = mysqli_connect($db_hostname, $db_username, $db_password);
$db_status = "connected";
$db_select = mysqli_select_db($db_server, $db_database);
if (!$db_server){
die("Unable to connect to MySQL: " . mysqli_connect_error($db_server)); 
$db_status = "not connected";
}else{ 
   //NEW SUBMISSION HANDLING CODE HERE
    if(trim($_POST['submit']) == "Submit") {
              $privatekey = "xxxxx";    
                $resp = recaptcha_check_answer ($privatekey,
                            $_SERVER["REMOTE_ADDR"],
                            $_POST["recaptcha_challenge_field"],
                            $_POST["recaptcha_response_field"]);

         if (!$resp->is_valid) {
                $message = "The reCAPTCHA wasn't entered correctly. Go back and try it again. (reCAPTCHA said: " . $resp->error . ")";
                // Get and clean the input data
                //$bedrooms = clean_string($db_server, $_POST["comments"]) ;
                // create the SQL query
                //$query = "SELECT Bedrooms, Price, Location, Company FROM table2 WHERE Bedrooms LIKE '%$Bedrooms%'";
                //mysqli_select_db($db_server, $db_database);
                //$result = mysqli_query($db_server, $query);
                //if (!$result) die("Database access failed: " . mysqli_error($db_server));
                 // if there are any rows, print out the contents
                //while($row = mysqli_fetch_array($result)) {
                        //$str_result .= $row['Bedrooms'] . " (" .
                                        //$row['Price'] . "), " .
                                        //$row['Location'] . ", who voted " .
                                        //$row['Company'] . " to raising tuition fees.<br />";
                        //if($str_result == "") $str_result = "No data found";
                        //$message = "Your search found the following information<br />:";
                        //mysqli_free_result($result);
                        //Print out existing comment
                        $query = "SELECT * FROM comments";
                        $result = mysqli_query($db_server, $query);
                        if (!$result) die("Database access failed: " . mysqli_error($db_server)); while($row = mysqli_fetch_array($result)){
                        } $str_comments .= "<p>" . $row['comment'] . "</p>";
                        mysqli_free_result($result);}
                        } else {
                            //$str_result = 'No MP was requested';
                            //Get any submitted comments and insert
                            //$comment = clean_string($db_server, $_POST['comment']);
                            if ($comment != '') {
                                    $query = "INSERT INTO comments (comment) VALUES ('$comment')";
                                    mysqli_select_db($db_server, $db_database);
                                    mysqli_query($db_server, $query) or
                                                 die("Insert failed: " . mysqli_error($db_server));
                                    $message = "Thanks for your comment!";

}
}
}
//}
//require_once “db_close.php”;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="home.css" rel="stylesheet" type="text/css"/>
<title>Home</title>
</head>

<body>
<div id="middle">
<h2><strong>HELLO!</strong></h2>
<h2>Welcome to <strong>Cosy Cribs</strong> website!</h2>
<p>This website combines all the possible lettings available to YOU from the most prefered letting companies in the great city of Leeds!</p>
<p>It was recognised that when students attempt to let a house for the next year, there were far too many different websites and companies visit; making the whole ordeal of finding a house more stressful then needs be!</p>
<p>We, at <strong>Cosy Cribs</strong>, decided that your lives needed to be made easier, and so we announce a website that provides you with all of the lettings from these different companies - all on one website - and links to the house you like.</p>
<h2>ENJOY!</h2>
</div>
<form id="comments" action="home.php" method="post"> <select name="comments">
</select>
<h1>Do you have a comment on preferred company or number of bedrooms?</h1>
Comment: <textarea rows="2" cols="30" name="comment"></textarea>

<input type="submit" id="submit" name="submit" value="Submit" />
<?php echo $message;
    echo $str_result;
?>
<?php
    require_once('recaptcha/recaptchalib.php');
        $publickey = "xxxxx";
    echo recaptcha_get_html($publickey);
?>
<?php echo $recaptcha_form;   //Close connection!
   mysqli_close($db_server);
?>
</form>
</body>
</html>
  • 写回答

1条回答 默认 最新

  • douhe4608 2013-12-27 12:26
    关注

    Your require won't be executed if the condition it is in evaluates to false.

    You should move the require outside of any conditional.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧