Since the original captcha thread is locked, I thought I'd try replying here... I've been using the build a blog tutorial, and it's wonderful, truly, but I too keep getting those spam comments... I tried the JS implement, but it didn't do the trick.
So I tried using captcha instead. However, using the code for process.php provided in the topic referred to, it doesn't work - I get connection errors. Which is logical, considering there's no place in that code where process.php is provided with the info to connect to my database. I've tried putting in the info below the captcha code, where it was placed in the pre-captcha process.php, but it still doesn't work.
Here's the error I get:
Warning: mysql_real_escape_string() [
function.mysql-real-escape-string]: Access denied for user 'aicon'@'localhost' (using password: NO) in
/path/colligo/process.php on line
53
aicon is not my username, so I'm assuming it's some default. Here's what my process.php looks like now (obviously I've exchanged the mysql connection info with my own):
CODE
<?php
if (isset($_POST['submit_comment'])) {
function verifycaptcha() {
@session_start();
$verifyimage = trim(strip_tags($_POST['verifyimage']));
if (isset($_SESSION['encoded_string']) && $verifyimage == $_SESSION['encoded_string']) {
$verifiedimg = true;
}
else {
$verifiedimg = false;
}
return $verifiedimg;
}
if (!verifycaptcha()) {
if (isset($_SESSION['encoded_string']) && isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-36000, '/');
$_SESSION = array();
session_destroy();
}
include("header.php");
echo "<h2>Error</h2>\n\n<p>Wrong image verification text entered. Please go back, refresh the page, and try again.</p>";
include("footer.php");
exit;
}
if (isset($_SESSION['encoded_string']) && isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-36000, '/');
$_SESSION = array();
session_destroy();
}
if (empty($_POST['name']) || empty($_POST['email']) || empty($_POST['comment'])) {
die("You have forgotten to fill in one of the required fields! Please make sure you submit a name, e-mail address and comment.");
}
$entry = htmlspecialchars(strip_tags($_POST['entry']));
$timestamp = htmlspecialchars(strip_tags($_POST['timestamp']));
$name = htmlspecialchars(strip_tags($_POST['name']));
$email = htmlspecialchars(strip_tags($_POST['email']));
$url = htmlspecialchars(strip_tags($_POST['url']));
$comment = htmlspecialchars(strip_tags($_POST['comment']));
$comment = nl2br($comment);
if (get_magic_quotes_gpc()) {
$comment = stripslashes($comment);
$name = stripslashes($name);
$email = stripslashes($email);
$url = stripslashes($url);
$timestamp = stripslashes($timestamp);
$entry = stripslashes($entry);
}
$comment = mysql_real_escape_string($comment);
$name = mysql_real_escape_string($name);
$email = mysql_real_escape_string($email);
$url = mysql_real_escape_string($url);
$timestamp = mysql_real_escape_string($timestamp);
$entry = mysql_real_escape_string($entry);
if (!eregi("^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) {
die("The e-mail address you submitted does not appear to be valid. Please go back and correct it.");
}
mysql_connect ('localhost', 'username', 'password');
mysql_select_db ('database');
$result = mysql_query("INSERT INTO $comments (entry, timestamp, name, email, url, comment) VALUES ('$entry','$timestamp','$name','$email','$url','$comment')") or die("Could not add comment: " . mysql_error());
header("Location: Entry.php?id=" . $entry);
}
else {
die("Error: you cannot access this page directly.");
}
?>
It might be some obvious error, but I know nothing about this sort of thing, so please bear with me.