#1 xpp1000
验证码文件
session_start();
//生成验证码图片
Header("Content-type: image/PNG");
$im = imagecreate(44,18);
$back = ImageColorAllocate($im, 245,245,245);
imagefill($im,0,0,$back); //背景
srand((double)microtime()*1000000);
//生成4位数字
for($i=0;$i<4;$i++){
$font = ImageColorAllocate($im, rand(100,255),rand(0,100),rand(100,255));
$authnum=rand(1,9);
$vcodes.=$authnum;
imagestring($im, 5, 2+$i*10, 1, $authnum, $font);
}
for($i=0;$i<100;$i++) //加入干扰象素
{
$randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
}
ImagePNG($im);
ImageDestroy($im);
$_SESSION['VCODE'] = $vcodes;
?>
注册处理程序
class reg extends spController
{
function index()
{
$this->display("reg.html");}
function check()
{
$user=$this->spArgs("user");
$email=$this->spArgs("email");
$password=md5($this->spArgs("password"));
$code=$this->spArgs("code");
$sql="select * from tbl_user where login_name='$user'";
$sp=spClass("tbl_user");
$fo=$sp->findSql($sql);
if($fo)
{
$a=1;
}
else
{
//echo "恭喜你此用户名可以注册";
$a=0;
}
$sdf="select * from tbl_user where email='$email'";
$fo1=$sp->findSql($sdf);
if($fo1)
{
//echo "此邮箱已存在";
$b=1;
}
else
{
//echo "恭喜你此邮箱可以注册";
$b=0;
}
$c=$a+$b;
if($c==0)
{
if(($_SESSION['VCODE'] == $code) && !empty($code))
{
$sql="insert into tbl_user (login_name,login_pass,email,type) value ('$user','$password','$email','20')";
$sp->Runsql($sql);
echo "添加成功";
}
else
{
echo"验证码不正确";
}
}
else
{
echo "用户名或邮箱重复,不可以注册";
}
}
function check4()
{
$user=$this->spArgs("user");
$email=$this->spArgs("email");
$password=md5($this->spArgs("password"));
$code=$this->spArgs("code");
$sql="select * from tbl_user where login_name='$user'";
$sp=spClass("tbl_user");
$fo=$sp->findSql($sql);
if($fo)
{
$a=1;
}
else
{
//echo "恭喜你此用户名可以注册";
$a=0;
}
$sdf="select * from tbl_user where email='$email'";
$fo1=$sp->findSql($sdf);
if($fo1)
{
//echo "此邮箱已存在";
$b=1;
}
else
{
//echo "恭喜你此邮箱可以注册";
$b=0;
}
$c=$a+$b;
if($c==0)
{
if(($_SESSION['VCODE'] == $code) && !empty($code))
{
$sql="insert into tbl_user (login_name,login_pass,email,type) value ('$user','$password','$email','10')";
$sp->Runsql($sql);
echo "添加成功";
}
else
{
echo"验证码不正确";
}
}
else
{
echo "用户名或邮箱重复,不可以注册";
}
}
function checks()
{
$user=$this->spArgs("user");
//$email=$this->spArgs("email");
//$password=$this->spArgs("password");
//$code=$this->spArgs("code");
$sql="select * from tbl_user where login_name='$user'";
$sp=spClass("tbl_user");
$fo=$sp->findSql($sql);
if($fo)
{
//$a=1;
echo "对不起此用户不名可以注册";
}
else
{
echo "恭喜你此用户名可以注册";
//$a=0;
}
}
function check1()
{
$email=$this->spArgs("email");
if(strstr($email,"@"))
{$sql="select * from tbl_user where email='$email'";
$sp=spClass("tbl_user");
$fo=$sp->findSql($sql);
if($fo)
{
//$a=1;
echo "对不起此邮箱不可以注册";
}
else
{
echo "恭喜你此邮箱可以注册";
//$a=0;
}
}
else
{
echo "邮箱格式不正确";
}
}
function check2()
{
$code=$this->spArgs("code");
if(($_SESSION['VCODE'] == $code) && !empty($code))
{
echo "验证码输入正确";
}
else
{
echo "验证码输入错误";
}
}
}
?>
2010-12-09 12:09:13