php验证码 怎么弄

libero2014 2012-02-12 09:23:24
跪求高手 加我QQ779846529
...全文
235 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
libero2014 2012-02-16
  • 打赏
  • 举报
回复
代码如上 求帮忙啊
lession 2012-02-16
  • 打赏
  • 举报
回复
这里有代码,我就是这样做的
http://www.lession.net/blog/473.html
libero2014 2012-02-15
  • 打赏
  • 举报
回复
<?php require_once('Connections/conn.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>




======================================================================



怎样通过验证码,才能提交内容,,可是每次验证码输错了,,内容却被提交了
码无边 2012-02-14
  • 打赏
  • 举报
回复
贴出你的疑问,不要说,不知道。
xb12369 2012-02-14
  • 打赏
  • 举报
回复
不会验证码总会百度吧???

直接百度一下!!!
yixi_xiangyi 2012-02-13
  • 打赏
  • 举报
回复
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" />
?>
cezanneluo 2012-02-13
  • 打赏
  • 举报
回复
随机选取数字或字母再以图片形式显示出来就行啦
libero2014 2012-02-13
  • 打赏
  • 举报
回复
能把你QQ给我 吗?这样很不方便。[Quote=引用 6 楼 phpnewnew 的回复:]
引用 5 楼 zifang20 的回复:

引用 3 楼 cezanneluo 的回复:
随机选取数字或字母再以图片形式显示出来就行啦
这个 会 就是一直判断验证码的代码 总是有问题。

那你就把你的代码给贴出来 别人才好知道是哪有问题,这么说别人怎么判断?
[/Quote]
黄袍披身 2012-02-13
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 zifang20 的回复:]

引用 3 楼 cezanneluo 的回复:
随机选取数字或字母再以图片形式显示出来就行啦
这个 会 就是一直判断验证码的代码 总是有问题。
[/Quote]
那你就把你的代码给贴出来 别人才好知道是哪有问题,这么说别人怎么判断?
libero2014 2012-02-13
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 cezanneluo 的回复:]
随机选取数字或字母再以图片形式显示出来就行啦
[/Quote]这个 会 就是一直判断验证码的代码 总是有问题。
libero2014 2012-02-12
  • 打赏
  • 举报
回复
还是 不会 能否帮帮忙 很急
黄袍披身 2012-02-12
  • 打赏
  • 举报
回复
有什么怎么弄的嘛?网上很多现成的代码复制一个就能用了。

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧