php 图片验证代码问题!!
<?phpsession_start();//session_register('SafeCode');?><SCRIPTlanguage=javascript><!--...
<?php
session_start();
//session_register('SafeCode');
?>
<SCRIPT language=javascript>
<!--
function CheckForm()
{
if(document.Login.u_name.value=="")
{
alert("请输入用户名!");
document.Login.u_name.focus();
return false;
}
if(document.Login.u_pass.value == "")
{
alert("请输入密码!");
document.Login.u_pass.focus();
return false;
}
if (document.Login.CheckCode.value==""){
alert ("请输入您的验证码!");
document.Login.CheckCode.focus();
return(false);
}
}
//-->
</SCRIPT>
<script language="javascript">
var vimg_src = "1.php";
function chg_vimg()
{
var vimg = document.getElementById("vimg");
vimg.src = vimg_src + "?" + Math.random();
}
</script>
<?php
if ($deng){
if($CheckCode != $_SESSION['SafeCode'] || empty($CheckCode)){
echo "<script>alert('校验码不正确!');window.location.href='index.php';</script>";
exit;
}
$u_pass1=md5($u_pass);
$sql = "select * from user where name='$u_name' and pass='$u_pass1' limit 0,1";
$rs = mysql_query($sql);
while ($row = mysql_fetch_array($rs, MYSQL_ASSOC)){
$_SESSION['u_admin_name'] = $row['u_name'];
echo "<script>window.location.href='main.php';</script>";
exit;
}
echo "<script>alert('用户名或密码不正确!');window.location.href='index.php';</script>";
exit;
}
?>
<TABLE cellSpacing=0 cellPadding=0 width=561 border=0>
<FORM name=Login onSubmit="return CheckForm();" action="index.php?deng=deng" method=post target=_parent>
<TBODY>
<TR>
<TD width=75 rowSpan=2>用户登录</TD>
<TD width=126><FONT color=#043bc9>用户名称:</FONT></TD>
<TD width=39 rowSpan=2> </TD>
<TD width=131><FONT color=#043bc9>用户密码:</FONT></TD>
<TD colspan="2"><font color=#043bc9>验证码:</font></TD>
<TD colSpan=2 rowspan="2"><input type="submit" value="提交"></TD>
</TR>
<TR>
<TD><INPUT name=u_name></TD>
<TD><INPUT name=u_pass type=password ></TD>
<TD width="33"><input maxlength=4 size=6
name=CheckCode></TD>
<TD width=53><font color=#00cc33><a href='javascript:chg_vimg();' tabindex='-1' ><img src="1.php" id=vimg title="看不清换一个!" border="0"></a></font></TD>
</TR></TBODY>
</FORM>
</TABLE>
其中:
<script language="javascript">
var vimg_src = "1.php";
function chg_vimg()
{
var vimg = document.getElementById("vimg");
vimg.src = vimg_src + "?" + Math.random();
}
</script>
这段代码啥意思?帮解释下!!
1.php
<?
//checkNum.php
session_start();
function random($len){
$srcstr="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
mt_srand();
$strs="";
for($i=0;$i<$len;$i++){
$strs.=$srcstr[mt_rand(0,35)];
}
return strtoupper($strs);
}
$str=random(4);
$width = 50;
$height = 22;
@header("Content-Type:image/png");
$_SESSION["code"] = $str;
//echo $str;
$im=imagecreate($width,$height);
$back=imagecolorallocate($im,0xFF,0xFF,0xFF);
$pix=imagecolorallocate($im,187,230,147);
$font=imagecolorallocate($im,41,163,238);
for($i=0;$i<1500;$i++)
{
imagesetpixel($im,mt_rand(0,$width),mt_rand(0,$height),$pix);
}
imagestring($im, 5, 7, 4,$_SESSION["code"], $font);
imagerectangle($im,0,0,$width-1,$height-1,$font);
imagepng($im);
imagedestroy($im);
?>
这个 vimg.src = vimg_src + "?" + Math.random();
不明白怎么重新生成验证码的 展开
session_start();
//session_register('SafeCode');
?>
<SCRIPT language=javascript>
<!--
function CheckForm()
{
if(document.Login.u_name.value=="")
{
alert("请输入用户名!");
document.Login.u_name.focus();
return false;
}
if(document.Login.u_pass.value == "")
{
alert("请输入密码!");
document.Login.u_pass.focus();
return false;
}
if (document.Login.CheckCode.value==""){
alert ("请输入您的验证码!");
document.Login.CheckCode.focus();
return(false);
}
}
//-->
</SCRIPT>
<script language="javascript">
var vimg_src = "1.php";
function chg_vimg()
{
var vimg = document.getElementById("vimg");
vimg.src = vimg_src + "?" + Math.random();
}
</script>
<?php
if ($deng){
if($CheckCode != $_SESSION['SafeCode'] || empty($CheckCode)){
echo "<script>alert('校验码不正确!');window.location.href='index.php';</script>";
exit;
}
$u_pass1=md5($u_pass);
$sql = "select * from user where name='$u_name' and pass='$u_pass1' limit 0,1";
$rs = mysql_query($sql);
while ($row = mysql_fetch_array($rs, MYSQL_ASSOC)){
$_SESSION['u_admin_name'] = $row['u_name'];
echo "<script>window.location.href='main.php';</script>";
exit;
}
echo "<script>alert('用户名或密码不正确!');window.location.href='index.php';</script>";
exit;
}
?>
<TABLE cellSpacing=0 cellPadding=0 width=561 border=0>
<FORM name=Login onSubmit="return CheckForm();" action="index.php?deng=deng" method=post target=_parent>
<TBODY>
<TR>
<TD width=75 rowSpan=2>用户登录</TD>
<TD width=126><FONT color=#043bc9>用户名称:</FONT></TD>
<TD width=39 rowSpan=2> </TD>
<TD width=131><FONT color=#043bc9>用户密码:</FONT></TD>
<TD colspan="2"><font color=#043bc9>验证码:</font></TD>
<TD colSpan=2 rowspan="2"><input type="submit" value="提交"></TD>
</TR>
<TR>
<TD><INPUT name=u_name></TD>
<TD><INPUT name=u_pass type=password ></TD>
<TD width="33"><input maxlength=4 size=6
name=CheckCode></TD>
<TD width=53><font color=#00cc33><a href='javascript:chg_vimg();' tabindex='-1' ><img src="1.php" id=vimg title="看不清换一个!" border="0"></a></font></TD>
</TR></TBODY>
</FORM>
</TABLE>
其中:
<script language="javascript">
var vimg_src = "1.php";
function chg_vimg()
{
var vimg = document.getElementById("vimg");
vimg.src = vimg_src + "?" + Math.random();
}
</script>
这段代码啥意思?帮解释下!!
1.php
<?
//checkNum.php
session_start();
function random($len){
$srcstr="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
mt_srand();
$strs="";
for($i=0;$i<$len;$i++){
$strs.=$srcstr[mt_rand(0,35)];
}
return strtoupper($strs);
}
$str=random(4);
$width = 50;
$height = 22;
@header("Content-Type:image/png");
$_SESSION["code"] = $str;
//echo $str;
$im=imagecreate($width,$height);
$back=imagecolorallocate($im,0xFF,0xFF,0xFF);
$pix=imagecolorallocate($im,187,230,147);
$font=imagecolorallocate($im,41,163,238);
for($i=0;$i<1500;$i++)
{
imagesetpixel($im,mt_rand(0,$width),mt_rand(0,$height),$pix);
}
imagestring($im, 5, 7, 4,$_SESSION["code"], $font);
imagerectangle($im,0,0,$width-1,$height-1,$font);
imagepng($im);
imagedestroy($im);
?>
这个 vimg.src = vimg_src + "?" + Math.random();
不明白怎么重新生成验证码的 展开
4个回答
展开全部
<script language="javascript">
var vimg_src = "1.php";
function chg_vimg()
{
var vimg = document.getElementById("vimg");
//获取vimg 的dom
vimg.src = vimg_src + "?" + Math.random();
//为img标签的src属性赋值Math.random()生成一个随机数,具体目的是啥得把1.php发来看看才知道,估计是为了生成不相同的验证码用的!~~~
}
</script>
//本质是换验证码图片,让1.php这个页面从新生成一个验证码,并显示
var vimg_src = "1.php";
function chg_vimg()
{
var vimg = document.getElementById("vimg");
//获取vimg 的dom
vimg.src = vimg_src + "?" + Math.random();
//为img标签的src属性赋值Math.random()生成一个随机数,具体目的是啥得把1.php发来看看才知道,估计是为了生成不相同的验证码用的!~~~
}
</script>
//本质是换验证码图片,让1.php这个页面从新生成一个验证码,并显示
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
JS刷新验证码验证码写在1.PHP中的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询