php验证码 怎么弄 跪求高手 加我QQ779846529 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1、假如你的是login.php页面:在此页面下,<?php include ("conn.php"); //这个是连接Mysql的session_start();echo $_SESSION[check_pic];if ($_POST) { $code=$_POST[code]; if($code!=$_SESSION[check_pic]) echo "<script>alert('验证码有误!');location.href='login.php';</script>"; }?><form id="form1" name="form1" method="post" action="" ><input name="code" type="text" id="code" size="8" /> <img src="inc/vCode.php" alt="验证码" width="55" height="30" align="absmiddle" style="cursor:pointer" onclick="javascript:this.src='inc/vCode.php?tm='+Math.random()" /><input type="submit" name="button" id="button" value="提交" /></form>2、src='inc/vCode.php?tm='+Math.random()中的inc/vCode.php,是指当前目录下的inc文件夹下,要放个vCode.php,你新建个vCode.php,代码如下,你粘贴即可:<?php /* * 放一个font.ttc字体到目录下 $num 字符个数 $size 字符大小 颜色随机 */ // vCode ******** function vCode($num = 4, $size = 20, $width = 0, $height = 0) { session_start(); !$width && $width = $num * $size * 4 / 5 + 5; !$height && $height = $size +10; // 去掉了 0 1 O l 等 $str = "23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVW"; $code = ''; for ($i = 0; $i < $num; $i++) { $code .= $str[mt_rand(0, strlen($str) - 1)]; } $_SESSION[check_pic]=$code; // 画图像 $im = imagecreatetruecolor($width, $height); // 定义要用到的颜色 $back_color = imagecolorallocate($im, 235, 236, 237); $boer_color = imagecolorallocate($im, 118, 151, 199); $text_color = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120)); // 画背景 imagefilledrectangle($im, 0, 0, $width, $height, $back_color); // 画边框 imagerectangle($im, 0, 0, $width -1, $height -1, $boer_color); // 画干扰线 for ($i = 0; $i < 5; $i++) { $font_color = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); imagearc($im, mt_rand(- $width, $width), mt_rand(- $height, $height), mt_rand(30, $width * 2), mt_rand(20, $height * 2), mt_rand(0, 360), mt_rand(0, 360), $font_color); } // 画干扰点 for ($i = 0; $i < 50; $i++) { $font_color = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $font_color); } // 画验证码 imagefttext($im, $size, 0, 5, $size +3, $text_color, 'simkai.ttf', $code); header("Cache-Control: max-age=1, s-maxage=1, no-cache, must-revalidate"); header("Content-type: image/png"); imagepng($im); imagedestroy($im); } vCode(4, 20);// 4个字符,大小为20 //调用方法:<img src="inc/vcode.php" />?> <?php require_once('Connections/conn.php'); ?><?php session_start();?><?phpif (!function_exists("GetSQLValueString")) {function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $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;}}$editFormAction = $_SERVER['PHP_SELF'];if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);}if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO user_zc (username, pass, phonenumber, realname, sex) VALUES (%s, %s, %s, %s, %s)", GetSQLValueString($_POST['username'], "text"), GetSQLValueString($_POST['pass'], "text"), GetSQLValueString($_POST['phonenumber'], "int"), GetSQLValueString($_POST['realname'], "text"), GetSQLValueString($_POST['select'], "text"));if ($_POST['yzm'] !== $_SESSION["vocode"]) { header("location: ". "user_zcsb.php" );} mysql_select_db($database_conn, $conn); $Result1 = mysql_query($insertSQL, $conn) or die(mysql_error()); $insertGoTo = "user_zccg.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo));}?><!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><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>用户注册</title></head><body><form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST"> <table width="240" border="0"> <tr> <td height="54" colspan="2">会员账号注册</td> </tr> <tr> <td width="44" height="90">*用户名</td> <td width="186"><input name="username" type="text" id="username" maxlength="12" /></td> </tr> <tr> <td height="87">*密码</td> <td><label> <input name="pass" type="password" id="pass" /> </label></td> </tr> <tr> <td height="39">*性别</td> <td><label> <select name="select" id="select"> <option value="男">男</option> <option value="女">女</option> </select> </label></td> </tr> <tr> <td height="75">*手机</td> <td><label> <input name="phonenumber" type="text" id="phonenumber" /> </label></td> </tr> <tr> <td height="96">*真实姓名</td> <td><label> <input name="realname" type="text" id="realname" /> </label></td> </tr> <tr> <td height="68" colspan="2"><label>*验证码 <input name='yzm' type='text' id="yzm" size='5' /> <img src='vcode/vcode.php' alt="" border='0' align='absmiddle' /><br /> </label></td> </tr> <tr> <td height="130" colspan="2"><input type="submit" name="Submit" value="提交" /> <input type="reset" name="Submit2" value="重置" /></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1" /></form></body></html>======================================================================怎样通过验证码,才能提交内容,,可是每次验证码输错了,,内容却被提交了 这里有代码,我就是这样做的http://www.lession.net/blog/473.html PHP编程,表单查询数据后,数据特定显示方式求解? 求教一个php上传文件的诡异问题 如何写一个规则 处理文章URL地址 用户权限是保存到cookie还是实时到数据库里取? 求一份discuz架构图或者体系结构,高分求购 小妹在线求救一个奇怪的问题的 分页显示 MySQL的安装问题 高分求教:PHP+LDAP(iplanet Directory Server5.1)的问题!LDAP高手请进!! thinkPHP导航条出现这种情况怎么解决??求解答 PHP怎样销毁一个函数 祝贺 PhpNewnew 荣任 PHP-基础编程 版主
<?php
include ("conn.php"); //这个是连接Mysql的
session_start();
echo $_SESSION[check_pic];if ($_POST) {
$code=$_POST[code];
if($code!=$_SESSION[check_pic])
echo "<script>alert('验证码有误!');location.href='login.php';</script>";
}?>
<form id="form1" name="form1" method="post" action="" >
<input name="code" type="text" id="code" size="8" /> <img src="inc/vCode.php" alt="验证码" width="55" height="30" align="absmiddle" style="cursor:pointer" onclick="javascript:this.src='inc/vCode.php?tm='+Math.random()" />
<input type="submit" name="button" id="button" value="提交" />
</form>2、src='inc/vCode.php?tm='+Math.random()中的inc/vCode.php,是指当前目录下的inc文件夹下,要放个vCode.php,你新建个vCode.php,代码如下,你粘贴即可:
<?php
/*
* 放一个font.ttc字体到目录下
$num 字符个数
$size 字符大小
颜色随机
*/
// vCode ********
function vCode($num = 4, $size = 20, $width = 0, $height = 0) {
session_start();
!$width && $width = $num * $size * 4 / 5 + 5;
!$height && $height = $size +10;
// 去掉了 0 1 O l 等
$str = "23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVW";
$code = '';
for ($i = 0; $i < $num; $i++) {
$code .= $str[mt_rand(0, strlen($str) - 1)];
}
$_SESSION[check_pic]=$code;
// 画图像
$im = imagecreatetruecolor($width, $height);
// 定义要用到的颜色
$back_color = imagecolorallocate($im, 235, 236, 237);
$boer_color = imagecolorallocate($im, 118, 151, 199);
$text_color = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120)); // 画背景
imagefilledrectangle($im, 0, 0, $width, $height, $back_color);
// 画边框
imagerectangle($im, 0, 0, $width -1, $height -1, $boer_color);
// 画干扰线
for ($i = 0; $i < 5; $i++) {
$font_color = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
imagearc($im, mt_rand(- $width, $width), mt_rand(- $height, $height), mt_rand(30, $width * 2), mt_rand(20, $height * 2), mt_rand(0, 360), mt_rand(0, 360), $font_color);
}
// 画干扰点
for ($i = 0; $i < 50; $i++) {
$font_color = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $font_color);
}
// 画验证码
imagefttext($im, $size, 0, 5, $size +3, $text_color, 'simkai.ttf', $code);
header("Cache-Control: max-age=1, s-maxage=1, no-cache, must-revalidate");
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
}
vCode(4, 20);// 4个字符,大小为20
//调用方法:<img src="inc/vcode.php" />
?>
<?php session_start();?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$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;
}
}$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO user_zc (username, pass, phonenumber, realname, sex) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['username'], "text"),
GetSQLValueString($_POST['pass'], "text"),
GetSQLValueString($_POST['phonenumber'], "int"),
GetSQLValueString($_POST['realname'], "text"),
GetSQLValueString($_POST['select'], "text"));
if ($_POST['yzm'] !== $_SESSION["vocode"]) {
header("location: ". "user_zcsb.php" );
}
mysql_select_db($database_conn, $conn);
$Result1 = mysql_query($insertSQL, $conn) or die(mysql_error()); $insertGoTo = "user_zccg.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>用户注册</title>
</head><body>
<form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST">
<table width="240" border="0">
<tr>
<td height="54" colspan="2">会员账号注册</td>
</tr>
<tr>
<td width="44" height="90">*用户名</td>
<td width="186"><input name="username" type="text" id="username" maxlength="12" /></td>
</tr>
<tr>
<td height="87">*密码</td>
<td><label>
<input name="pass" type="password" id="pass" />
</label></td>
</tr>
<tr>
<td height="39">*性别</td>
<td><label>
<select name="select" id="select">
<option value="男">男</option>
<option value="女">女</option>
</select>
</label></td>
</tr>
<tr>
<td height="75">*手机</td>
<td><label>
<input name="phonenumber" type="text" id="phonenumber" />
</label></td>
</tr>
<tr>
<td height="96">*真实姓名</td>
<td><label>
<input name="realname" type="text" id="realname" />
</label></td>
</tr>
<tr>
<td height="68" colspan="2"><label>*验证码
<input name='yzm' type='text' id="yzm" size='5' />
<img src='vcode/vcode.php' alt="" border='0' align='absmiddle' /><br />
</label></td>
</tr>
<tr>
<td height="130" colspan="2"><input type="submit" name="Submit" value="提交" />
<input type="reset" name="Submit2" value="重置" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
</body>
</html>
======================================================================怎样通过验证码,才能提交内容,,可是每次验证码输错了,,内容却被提交了
http://www.lession.net/blog/473.html