下面我作的是PHP的登录功能:有验证码功能的:php
设计界面:mysql
登录功能网页:sql
<?php
session_start();
if(!empty($_POST['aaa'])){
if(strtoupper($_POST["yzm"])!=$_SESSION["vcode"])
{
die("<script>alert('验证码输入错误!');window.navigate('SR_1.php');</script>");
} //验证码部分:
$username = $_REQUEST['username']; //把会话的值存入到变量$username中
$_SESSION['username']=$username;
$password = $_REQUEST['password'];
mysql_connect('localhost','root','123456');
mysql_select_db('yy');
$sql = "select * from users where username=$username and password=$password";
$result=mysql_query($sql);
if(mysql_num_rows($result)>=1){
echo "<script>alert('登录成功,跳转留言本ing.');location='SR_7.php'</script>";
}else{
echo "<script>alert('登录失败:密码错误或用户不存在');</script>";
}
}
mysql_close();?>数组
<h1><img src="p_w_picpaths/1.jpg" width="200" height="200" /></h1><br />
<form method="post" name="aa">
<h1><font color="#FF0000">用户登录</font><font size="-1" color="#FF9900"></font></h1>
用户名:<input type="text" name="username" id="username" /><br />
密 码:
<input type="password" name="password" />
<br />
<br />
验证:<input name="yzm" type="text" style="width:32px; height:16px; background-color:#292929; border:solid 1px #7dbad7; font-size:12px; color:#6cd0ff" maxlength="4">
<img onClick="this.src=this.src+'?a=Math.random()'" src="SR_1-1.php" alt="看不清?请点击!"> //验证码的那张图片
<br>
<input type="submit" name="aaa" value="登录" />
<a href="SR_6.php">修改密码" </a>
</form>session
验证码的网页://这部分是能够实现的!但我仍是记不住,呵呵!dom
<?php
session_start();
$string="ABCDEFGHIJKLMNOPQRSTUVWXYZ23456789";//存储验证码内容
//1 产生随机数,存入str数组,vcode变量
$_SESSION["vcode"]="";
for($i=0;$i<4;$i++)
{
$str[$i]=$string[rand(0,33)];
//2 将输入存入session中
$_SESSION["vcode"].=$str[$i];
}ide
//3 建立图像
$w=80;//图像的宽高
$h=26;
$im=p_w_picpathcreatetruecolor($w,$h);//建立图像
$bg1=p_w_picpathcolorallocate($im,255,255,255);//白色
$bg2=p_w_picpathcolorallocate($im,0,0,0);//黑色
p_w_picpathfilledrectangle($im,0,0,$w,$h,$bg1);//绘制一个矩形
p_w_picpathrectangle($im,0,0,$w-1,$h-1,$bg2);//绘制边框
//生成雪花背景,干扰
for($i=1;$i<=200;$i++)
{
$x=rand(1,$w-9);
$y=rand(1,$h-9);
$color=p_w_picpathcolorallocate($im,rand(150,255),rand(150,255),rand(150,255));
p_w_picpathstring($im,1,$x,$y,"*",$color);
}
//4 将数据写入图像
for($i=0;$i<4;$i++)
{
$x=13+$i*($w-15)/4;//分配四个数的x位置
$y=rand(3,$h/3);//分配Y轴4个数位置
$color=p_w_picpathcolorallocate($im,rand(0,150),rand(0,150),rand(0,150));
p_w_picpathstring($im,5,$x,$y,$str[$i],$color);//将数据写入图像
}
header("Content-type:p_w_picpath/jpeg");
p_w_picpathjpeg($im);
?>post