Hi,
I developed a website with captcha image validation. I developed it with PHP Version 5.2.5 and i uploaded on PHP Version 4.3.11 server. Captcha image validation working with my server. But it is not working with my cient server. Here iam sending my code sample. Please help me to solve this problem.
enquiry.php
<?php session_start(); ?>
<html>
<body>
<?php
if (isset($_POST['submitBtn'])){
$secCode = isset($_POST['secCode']) ? strtolower($_POST['secCode']) : "";
if ($secCode == $_SESSION['securityCode']) {
echo "<p>The result code was valid!<br/></p>";
unset($_SESSION['securityCode']);
$result = true;
}
else {
echo "<p>Sorry the security code is invalid! Please try it again!</p>";
$result = false;
}
}
if ((!isset($_POST['submitBtn'])) || (!$result)){
?>
<form action="thanks.php" method="post" >
<table width="100%" border="0" align="center" cellpadding="1" cellspacing="1">
<tr>
<td>Company Name</td>
<td>
<input name="name" id="name" type="text" class="textbox" /></td>
</tr>
<tr>
<td>
Please describe your requirements:</td>
</tr>
<tr>
<td><textarea name="Requirement" class="textareaBig"></textarea></td>
</tr>
<tr>
<td>
Enter the code shown on image</td>
<td>
<input name="secCode" id="secCode" type="text" class="textbox" /></td>
<td>
<img src="securityCode.php" alt="security code" border="1" /></td>
</tr>
<tr>
<td align="center">
<input type="submit" name="submitBtn" value="Send" class="Bigbtn" />
</td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>
thanks.php
<?php
session_start();
$_POST['secCode']=strtolower($_POST['secCode']);
if($_POST['secCode']!=$_SESSION['securityCode']){
header("location:enquiry.php?msg=code not matching");
exit;
}
array($fieldNames);
array($fieldValues);
$email=$_REQUEST['email'];
$mailAddress = "vineeth.kumar@bhasin.in";
$i = 0;
while (list($key, $value) = each($HTTP_POST_VARS)) {
$fieldNames[$i] = $key;
$fieldValues[$i] = $value;
$i++;
}
while (list($key, $value) = each($HTTP_GET_VARS)) {
$fieldNames[$i] = $key;
$fieldValues[$i] = $value;
$i++;
}
sendEmail($mailAddress, $fieldNames, $fieldValues,$email);
function sendEmail($sendMail, $fieldNames, $fieldValues,$email) {
$to = $sendMail;
$subject = "General Comments/Enquiry/Suggestion";
$mailheaders = "From: $email\nReply-To: $email";
for ($i=0; $i < sizeof($fieldNames); $i++) {
if (!($fieldNames[$i] == 'redirect') && !($fieldNames[$i] == 'function') && !($fieldNames[$i] == 'mailAddress') && !($fieldNames[$i] == 'fileName')) {
if ( !($i == 0) ) {
$msg = $msg . "$fieldNames[$i] : $fieldValues[$i] \n";
}
else {
$msg = "$fieldNames[$i] : $fieldValues[$i] \n";
}
}
}
mail($to, $subject, $msg, $mailheaders);
}
?>
secCode.php
<?php
session_start();
$width = 120;
$height = 40;
$length = 5;
$baseList = '0123456789abcdfghjkmnpqrstvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$code = "";
$counter = 0;
$image = @imagecreate($width, $height) or die('Cannot initialize GD!');
for( $i=0; $i<10; $i++ ) {
imageline($image,
mt_rand(0,$width), mt_rand(0,$height),
mt_rand(0,$width), mt_rand(0,$height),
imagecolorallocate($image, mt_rand(150,255),
mt_rand(150,255),
mt_rand(150,255)));
}
for( $i=0, $x=0; $i<$length; $i++ ) {
$actChar = substr($baseList, rand(0, strlen($baseList)-1), 1);
$x += 10 + mt_rand(0,10);
imagechar($image, mt_rand(3,5), $x, mt_rand(5,20), $actChar,
imagecolorallocate($image, mt_rand(0,155), mt_rand(0,155), mt_rand(0,155)));
$code .= strtolower($actChar);
}
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
$_SESSION['securityCode'] = $code;
?>