October 29, 201015 yr Hi I've been trying to put recaptcha on my blog now for 4 days because of spammers. It works when I put it on the contact form but not the blog can anyone tell me where to put the serverside code which is this: <?php require_once('recaptchalib.php'); $privatekey = "your_private_key"; $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 die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." . "(reCAPTCHA said: " . $resp->error . ")"); } else { // Your code here to handle a successful verification } ?> In this code which is at the top of my blog page: (I've marked where I put it with 'I PUT IT HERE' and 'AND I TRIED IT HERE) // I PUT IT HERE <?php require_once('../Connections/blog.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } // AND I TRIED IT HERE $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "comment")) { $insertSQL = sprintf("INSERT INTO blogmain (name, email, `comment`) VALUES (%s, %s, %s)", GetSQLValueString($_POST['name'], "text"), GetSQLValueString($_POST['email'], "text"), GetSQLValueString($_POST['comment'], "text")); mysql_select_db($database_blog, $blog); $Result1 = mysql_query($insertSQL, $blog) or die(mysql_error()); $insertGoTo = "index.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } mysql_select_db($database_blog, $blog); $query_blogmain = "SELECT * FROM blogmain"; $blogmain = mysql_query($query_blogmain, $blog) or die(mysql_error()); $row_blogmain = mysql_fetch_assoc($blogmain); $totalRows_blogmain = mysql_num_rows($blogmain); ?> I would be greatful for any help Kelly
October 29, 201015 yr Hi I've been trying to put recaptcha on my blog now for 4 days because of spammers. It works when I put it on the contact form but not the blog can anyone tell me where to put the serverside code which is this: <?php require_once('recaptchalib.php'); $privatekey = "your_private_key"; $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 die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." . "(reCAPTCHA said: " . $resp->error . ")"); } else { // Your code here to handle a successful verification } ?> In this code which is at the top of my blog page: (I've marked where I put it with 'I PUT IT HERE' and 'AND I TRIED IT HERE) // I PUT IT HERE <?php require_once('../Connections/blog.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } // AND I TRIED IT HERE $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "comment")) { $insertSQL = sprintf("INSERT INTO blogmain (name, email, `comment`) VALUES (%s, %s, %s)", GetSQLValueString($_POST['name'], "text"), GetSQLValueString($_POST['email'], "text"), GetSQLValueString($_POST['comment'], "text")); mysql_select_db($database_blog, $blog); $Result1 = mysql_query($insertSQL, $blog) or die(mysql_error()); $insertGoTo = "index.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } mysql_select_db($database_blog, $blog); $query_blogmain = "SELECT * FROM blogmain"; $blogmain = mysql_query($query_blogmain, $blog) or die(mysql_error()); $row_blogmain = mysql_fetch_assoc($blogmain); $totalRows_blogmain = mysql_num_rows($blogmain); ?> I would be greatful for any help Kelly Did u build the blog from scratch? or is it something like wordpress?
October 29, 201015 yr Author Did u build the blog from scratch? or is it something like wordpress? Using Dreamweaver
October 31, 201015 yr hiya, could you post the var dump of $resp please. $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); // add me echo var_dump($resp);
Create an account or sign in to comment