I have the following script for my Guestbook and it works fine. But I came across a captcha script I would like to incorporate into the already existing Guestbook. I have attached the captcha files here.
Please, can anyone help me to readjust the Guestbook codes to accommodate the Captcha?
The Guestbook files are as follows:
global.inc.php:
<?php
function pt_register()
{
$num_args = func_num_args();
$vars = array();
if ($num_args >= 2) {
$method = strtoupper(func_get_arg(0));
if (($method != 'SESSION') && ($method != 'GET') && ($method != 'POST') && ($method != 'SERVER') && ($method != 'COOKIE') && ($method != 'ENV')) {
die('The first argument of pt_register must be one of the following: GET, POST, SESSION, SERVER, COOKIE, or ENV');
}
$varname = "HTTP_{$method}_VARS";
global ${$varname};
for ($i = 1; $i < $num_args; $i++) {
$parameter = func_get_arg($i);
if (isset(${$varname}[$parameter])) {
global $$parameter;
$$parameter = ${$varname}[$parameter];
}
}
} else {
die('You must specify at least two arguments');
}
}
?>
process.php:
<?php
echo "<title>Guestbook Processor</title>";
include("global.inc.php");
$errors=0;
$error="Error(s) occurred while processing your form input.<ul>";
pt_register('POST','Name');
pt_register('POST','Email');
pt_register('POST','WebSite');
pt_register('POST','Message');
$Message=preg_replace("/(\015\012)|(\015)|(\012)/"," <br />", $Message);if($Name=="" || $Email=="" || $Message=="" ){
$errors=1;
$error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
}
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$Email)){
$error.="<li>Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="Name: ".$Name."
Email: ".$Email."
Web Site: ".$WebSite."
Message: ".$Message."
";
$message = stripslashes($message);
mail("test@mysite.org","A visitor signed the Guestbook",$message,"From: Guestbook Processor");
$make=fopen("data.dat","a");
$to_put="";
$to_put .= $Name."|".$Email."|".$WebSite."|".$Message."
";
fwrite($make,$to_put);
echo '<meta http-equiv="refresh" content="0;url=thankyou.php" />';
}
?>
guestbook.php:
<html>
<head>
</head>
<body>
<div class="formwrap" id="formwrap">
<div id="formsit">
<form enctype="multipart/form-data" action="process.php" method="post">
<table width="411" border="0" align="center" cellpadding="5" cellspacing="5" bgcolor="#FFFFFF">
<tbody><tr align="left"><td width="10%" bgcolor="#D0DEF4" colspan="2"><p><font size="2" face="Verdana" color="#ffffff"><strong>
<!--- You can add a form title here ---->
</strong></font><strong><font size="2" face="Verdana" color="#000066"> </font></strong>
</p>
</p></td></tr><tr>
<td width="100%" bgcolor="#D0DEF4" colspan="2"><p><font size="2" face="Verdana"><strong><font size="2" face="Verdana" color="#000066">
<!--- You can add a brief form description here---->
<br>
</strong></font></p></td></tr><tr><td width="10%" bgcolor="#eff3f7" colspan="2"><font size="1" face="Verdana">Please fill in all fields marked with a <font color="#ff0000">*</font></font></td>
</tr><tr><td width="100" bgcolor="#F8FAFC" align="right"><font size="2" face="Verdana">Name:</font></td>
<td width="469" bgcolor="#F8FAFC"><font face="Verdana">
<input name="Name" type="text" size="40">
<font color="#ff0000">*</font></font></td>
</tr><tr><td width="100" bgcolor="#F8FAFC" align="right"><font size="2" face="Verdana">Email:</font></td>
<td width="469" bgcolor="#F8FAFC"><font face="Verdana">
<input name="Email" type="text" size="40">
<font color="#ff0000">*</font></font></td>
</tr><tr><td width="100" bgcolor="#F8FAFC" align="right"><font size="2" face="Verdana">Web Site:</font></td>
<td width="469" bgcolor="#F8FAFC"><font face="Verdana">
<input name="WebSite" type="text" size="40">
</font></td>
</tr><tr><td width="100" bgcolor="#F8FAFC" align="right"><font size="2" face="Verdana">Message:</font></td><td width="469" bgcolor="#F8FAFC"><font face="Verdana">
<textarea name="Message" rows="4" cols="30"></textarea>
<font color="#ff0000">*</font></font></td>
</tr>
<tr>
<td height="25" colspan="2" align="left" bgcolor="#F8FAFC"><img src="CaptchaSecurityImages.php?width=100&height=40&characters=5" /><br />
<label for="security_code">Type the security code: </label>
<input id="security_code" name="security_code" type="text" />
<span class="style1">*</span>
</td>
</tr>
<tr>
<td width="10%" height="25" colspan="2" align="center" bgcolor="#D0DEF4"><font size="2" face="Verdana">
<input type="submit" value="Submit Form">
<input type="reset" value="Reset Form">
</font></td>
</tr></tbody></table>
</form>
</div>
</body>
</html>