使用验证码处理一个相当简单的表单这是我第一次处理验证码,所以我使用的是预建设置“quickcaptcha 1.0”
目前一切正常表单,验证码,除了我认为它与变量之间的链接数量有关的过程?
这就是我认为应该发生的事情。表单显示给用户,用户输入信息。在提交按钮后通过“requestresult.php”检查验证码,如果成功则将其移交给“resultsettings.php”,然后在结果设置中将其发送到“requestprocess.php”,后者收集了包含中的变量初始 request.php 表单。
我不确定....现在它正在发送两封电子邮件,其中一封带有正文信息,没有附加任何输入信息,另一封在其下方根本没有任何内容。
这是代码。
请求.php:
<?
/* Subject and Email Variables */
$emailSubject = 'Request Form';
$webMaster = 'info@mywebhost.com';
/* Gathering Data Variables */
$nameField = $_POST['name'];
$aliasField = $_POST['alias'];
$cellField = $_POST['cell'];
$emailField = str_replace( "\r\n", '', $_POST['email'] );
$boardField = $_POST['board'];
$refname1Field = $_POST['refname1'];
$refcontact1Field = $_POST['refcontact1'];
$refname2Field = $_POST['refname2'];
$workinfoField = $_POST['workinfo'];
$worknameField = $_POST['workname'];
$workaddyField = $_POST['workaddy'];
$switchnoField = $_POST['switchno'];
$directnoField = $_POST['directno'];
?>
<!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>
<link href="nrlayouts.css" rel=stylesheet type=text/css />
<script type="text/javascript">
// <![CDATA[
function display(obj,id1,id2) {
txt = obj.options[obj.selectedIndex].value;
document.getElementById(id1).style.display = 'none';
document.getElementById(id2).style.display = 'none';
if ( txt.match(id1) ) {
document.getElementById(id1).style.display = 'block';
}
if ( txt.match(id2) ) {
document.getElementById(id2).style.display = 'block';
}
}
// ]]>
</script>
</head>
<body bgcolor="#CCC"><form action="requestresult.php" method="post">
<table width="540" border="0" cellspacing="5" cellpadding="0">
<tr>
<td width="250" align="right"><label for="name7">Full Name:</label> </td>
<td width="250" align="left"><input type="text" name="name" id="name" /> </td>
</tr>
<tr>
<td width="250" align="right"><label for="alias">Alias:</label></td>
<td width="250" align="left"><input type="text" name="alias" id="alias" /> </td>
</tr>
<tr>
<td width="250" align="right"><label for="cell">Cellphone:</label> </td>
<td width="250" align="left"><input type="text" name="cell" id="cell" /> </td>
</tr>
<tr>
<td width="250" align="right"><label for="email">Email:</label></td>
<td width="250" align="left"><input type="text" name="email" id="email" /> </td>
</tr>
<tr>
<td width="250" align="right"><label for="board">Board:</label></td>
<td width="250" align="left"><input type="text" name="board" id="board" /></td>
</tr>
<td class="title">References?</td>
<td class="field">
<select name="type" onchange="display(this,'References','workinfo');">
<option>Do you have References?:</option>
<option value="References">Yes</option>
<option value="workinfo">No</option>
</select>
</tr>
</thead>
<tfoot>
<tr>
<td class="title">Please Prove You are Human: <img src="quickcaptcha/imagebuilder.php" border="1"></td>
<td><input MAXLENGTH=8 SIZE=8 name="userstring" type="text" value=""></td>
<td></td>
</tr>
<tr>
<td class="align-center" colspan="2"><input type="submit" name="submit" value="Send Email!" /> <input type="reset" value="Reset" /></td>
</tr>
</tfoot>
<tbody id="References" style="display: none;">
<tr>
<td class="title">Reference Name:</td>
<td class="field"><input type="text" name="refname1" size="20" maxlength="20" /> </td>
</tr>
<tr>
<td class="title">Reference Contact:</td>
<td class="field"><input type="text" name="refcontact1" size="20" maxlength="30" /></td>
</tr>
<tr>
<td class="title">Reference Name:</td>
<td class="field"><input type="text" name="refname2" size="20" maxlength="20" /></td>
</tr>
<tr>
<td class="title">Reference Contact:</td>
<td class="field"><input type="text" name="refcontact2" size="20" maxlength="30" /></td>
</tr>
</tbody>
<tbody id="workinfo" style="display: none;">
<tr>
<td class="title">Work Information:</td>
<td class="field"><input type="text" name="workinfo" size="20" maxlength="30" /> </td>
</tr>
<tr>
<td class="title">Employer's Name:</td>
<td class="field"><input type="text" name="workname" size="20" maxlength="30" /></td>
</tr>
<tr>
<td class="title">Employer's Address:</td>
<td class="field"><input type="textarea" name="workaddy" size="20" maxlength="30" /></td>
</tr>
<tr>
<td class="title">Main Switchboard Number:</td>
<td class="field"><input type="text" name="switchno" size="20" maxlength="20"/> </td>
</tr>
<tr>
<td class="title">Direct Line:</td>
<td class="field"><input type="text" name="directno" size="20" maxlength="20" /> </td>
</tr>
</table>
</form>
</body>
</html>
请求设置.php
<?php
// This string contains allowable characters for the image.
// To reduce confusion, zero and the letter 'o' have been removed,
// and QuickCaptcha is NOT case-sensitive.
$acceptedChars = 'ABCDEFGHIJKLMNPQRSTUVWXYZ123456789';
// Number of characters in image.
$stringlength = 5;
// Where to go when the correct / incorrect code is entered.
$success = "requestprocess.php";
$failure = "failure.html";
// A value between 0 and 100 describing how much color overlap
// there is between text and other objects. Lower is more
// secure against bots, but also harder to read.
$contrast = 60;
// Various obfuscation techniques.
$num_polygons = 3; // Number of triangles to draw. 0 = none
$num_ellipses = 6; // Number of ellipses to draw. 0 = none
$num_lines = 0; // Number of lines to draw. 0 = none
$num_dots = 0; // Number of dots to draw. 0 = none
$min_thickness = 2; // Minimum thickness in pixels of lines
$max_thickness = 8; // Maximum thickness in pixles of lines
$min_radius = 5; // Minimum radius in pixels of ellipses
$max_radius = 15; // Maximum radius in pixels of ellipses
// How opaque should the obscuring objects be. 0 is opaque, 127
// is transparent.
$object_alpha = 75;
?>
请求结果.php:
<?php
include "requestsettings.php";
session_start();
$string = strtoupper($_SESSION['string']);
$userstring = strtoupper($_POST['userstring']);
session_destroy();
if (($string == $userstring) && (strlen($string) > 4)) {
header("Location: $success");
exit();
} else {
header("Location: $failure");
exit();
}
?>
请求进程.php
<?php
include_once "request.php";
$emailSubject = 'Request Form';
$webMaster = 'info@mywebhost.com';
$body = <<<EOD
<br><hr><br>
Name: $nameField <br>
Alias: $aliasField <br>
Cellphone: $cellField <br>
Email: $emailField <br>
Board: $boardField <br>
Reference Name1: $refname1Field <br>
Reference Contact1: $refcontact1Field <br>
Reference Name2: $refname2Field <br>
Reference Contact2: $refcontact2Field <br>
Work Information: $workinfoField <br>
Work Name: $worknameField <br>
Work Address: $workaddyField <br>
Switchboard Number: $switchnoField <br>
Direct Line: $directnoField <br>
EOD;
$headers = "From: $emailField\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);
/* Results rendered as HTML */
$result = "Thank you! Your request will be answered shortly.";
if($success){
echo "$result";
}else{
echo "There was an error with your submission";
exit;
}
?>
图像生成器.php
<?php
include "settings.php";
// Keep #'s reasonable.
$min_thickness = max(1,$min_thickness);
$max_thickness = min(20,$max_thickness);
// Make radii into height/width
$min_radius *= 2;
$max_radius *= 2;
// Renormalize contrast
$contrast = 255 * ($contrast / 100.0);
$o_contrast = 1.3 * $contrast;
$width = 15 * imagefontwidth (5);
$height = 2.5 * imagefontheight (5);
$image = imagecreatetruecolor ($width, $height);
imagealphablending($image, true);
$black = imagecolorallocatealpha($image,0,0,0,0);
// Build the validation string
$max = strlen($acceptedChars)-1;
$password = NULL;
for($i=0; $i < $stringlength; $i++) {
$cnum[$i] = $acceptedChars{mt_rand(0, $max)};
$password .= $cnum[$i];
}
// Add string to image
$rotated = imagecreatetruecolor (70, 70);
$x = 0;
for ($i = 0; $i < $stringlength; $i++) {
$buffer = imagecreatetruecolor (20, 20);
$buffer2 = imagecreatetruecolor (40, 40);
// Get a random color
$red = mt_rand(0,255);
$green = mt_rand(0,255);
$blue = 255 - sqrt($red * $red + $green * $green);
$color = imagecolorallocate ($buffer, $red, $green, $blue);
// Create character
imagestring($buffer, 5, 0, 0, $cnum[$i], $color);
// Resize character
imagecopyresized ($buffer2, $buffer, 0, 0, 0, 0, 25 + mt_rand(0,12), 25 + mt_rand(0,12), 20, 20);
// Rotate characters a little
$rotated = imagerotate($buffer2, mt_rand(-25, 25),imagecolorallocatealpha($buffer2,0,0,0,0));
imagecolortransparent ($rotated, imagecolorallocatealpha($rotated,0,0,0,0));
// Move characters around a little
$y = mt_rand(1, 3);
$x += mt_rand(2, 6);
imagecopymerge ($image, $rotated, $x, $y, 0, 0, 40, 40, 100);
$x += 22;
imagedestroy ($buffer);
imagedestroy ($buffer2);
}
// Draw polygons
if ($num_polygons > 0) for ($i = 0; $i < $num_polygons; $i++) {
$vertices = array (
mt_rand(-0.25*$width,$width*1.25),mt_rand(-0.25*$width,$width*1.25),
mt_rand(-0.25*$width,$width*1.25),mt_rand(-0.25*$width,$width*1.25),
mt_rand(-0.25*$width,$width*1.25),mt_rand(-0.25*$width,$width*1.25)
);
$color = imagecolorallocatealpha ($image, mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), $object_alpha);
imagefilledpolygon($image, $vertices, 3, $color);
}
// Draw random circles
if ($num_ellipses > 0) for ($i = 0; $i < $num_ellipses; $i++) {
$x1 = mt_rand(0,$width);
$y1 = mt_rand(0,$height);
$color = imagecolorallocatealpha ($image, mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), $object_alpha);
// $color = imagecolorallocate($image, mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), mt_rand(0,$o_contrast));
imagefilledellipse($image, $x1, $y1, mt_rand($min_radius,$max_radius), mt_rand($min_radius,$max_radius), $color);
}
// Draw random lines
if ($num_lines > 0) for ($i = 0; $i < $num_lines; $i++) {
$x1 = mt_rand(-$width*0.25,$width*1.25);
$y1 = mt_rand(-$height*0.25,$height*1.25);
$x2 = mt_rand(-$width*0.25,$width*1.25);
$y2 = mt_rand(-$height*0.25,$height*1.25);
$color = imagecolorallocatealpha ($image, mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), $object_alpha);
imagesetthickness ($image, mt_rand($min_thickness,$max_thickness));
imageline($image, $x1, $y1, $x2, $y2 , $color);
}
// Draw random dots
if ($num_dots > 0) for ($i = 0; $i < $num_dots; $i++) {
$x1 = mt_rand(0,$width);
$y1 = mt_rand(0,$height);
$color = imagecolorallocatealpha ($image, mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), mt_rand(0,$o_contrast),$object_alpha);
imagesetpixel($image, $x1, $y1, $color);
}
session_start();
$_SESSION['string'] = $password;
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>