Smarty模版下的用户注册和登录系统.docx

上传人:b****5 文档编号:8661456 上传时间:2023-02-01 格式:DOCX 页数:24 大小:302.77KB
下载 相关 举报
Smarty模版下的用户注册和登录系统.docx_第1页
第1页 / 共24页
Smarty模版下的用户注册和登录系统.docx_第2页
第2页 / 共24页
Smarty模版下的用户注册和登录系统.docx_第3页
第3页 / 共24页
Smarty模版下的用户注册和登录系统.docx_第4页
第4页 / 共24页
Smarty模版下的用户注册和登录系统.docx_第5页
第5页 / 共24页
点击查看更多>>
下载资源
资源描述

Smarty模版下的用户注册和登录系统.docx

《Smarty模版下的用户注册和登录系统.docx》由会员分享,可在线阅读,更多相关《Smarty模版下的用户注册和登录系统.docx(24页珍藏版)》请在冰豆网上搜索。

Smarty模版下的用户注册和登录系统.docx

Smarty模版下的用户注册和登录系统

Smarty模版下的用户注册和登录系统

把Smarty模版加到工程中,在templates中建立的文件为样式

Smarty配置文件

php

include_once("Smarty/Smarty.class.php");//包含smarty类文件

$smarty=newSmarty();//建立smarty实例对象$smarty

$smarty->config_dir="Smarty/Config_File.class.php";//目录变量

$smarty->caching=false;//是否使用缓存,项目在调试期间,不建议启用缓存

$smarty->template_dir="./templates";//设置模板目录

$smarty->compile_dir="./templates_c";//设置编译目录

$smarty->cache_dir="./smarty_cache";//缓存文件夹

//----------------------------------------------------

//左右边界符,默认为{},但实际应用当中容易与JavaScript相冲突

//----------------------------------------------------

$smarty->left_delimiter="{";

$smarty->right_delimiter="}";

>

建立用户信息数据库

数据库初始化

php

session_start();

$conn=@mysql_connect("localhost","root","")ordie("数据库链接错误");

mysql_select_db("meal",$conn);

mysql_query("setnames'GBK'");

>

用户注册页面

{$title}

--不同的表单中的input按钮的id和name名称不能一样-->

用户注册

50px">


  用户名:

160px;height:

24px;"/> 

#800000">*

#800000"id="regusertext">


注册密码:

160px;height:

24px;"/> 

#800000">*

#800000"id="regpwtext">


确认密码:

160px;height:

24px;"/> 

#800000">*

#800000"id="regpw1text">


联系电话:

160px;height:

24px;"/> 

#800000">*

#800000"id="regteltext">


     QQ:

160px;height:

24px;"/> 

#800000">*

#800000"id="regqqtext">


 E-mail:

 

160px;height:

24px;"/> 

#800000">*

#800000"id="regemailtext">


120px;">

        

/*两种触发事件不能写在一起*/

$(document).ready(function(){

/*判断用户注册输入信息不能为空*/

//鼠标离开输入框后提示信息,input的blur()事件:

失去焦点的时候触发;

$("#reguser").blur(function(){//对id为user的输入框进行判断

if($("#reguser").val()=="")

{

$("#regusertext").html("用户名不能为空!

");

}

});

$("#regpassword").blur(function(){

if($("#regpassword").val()=="")

{

$("#regpwtext").html("密码不能为空!

");

}

});

$("#regpassword1").blur(function(){

if($("#regpassword1").val()=="")

{

$("#regpw1text").html("确认密码不能为空!

");

}

//用户注册判断两次输入的密码是否正确

elseif($("#regpassword1").val()!

=$("#regpassword").val())

{

$("#regpw1text").html("密码不一致");

$("#regpassword1").val("");//清空内容

//$("#password1").focus();//输入框获取焦点

}

});

$("#regtel").blur(function(){

if($("#regtel").val()=="")

{

$("#regteltext").html("联系电话不能为空!

");

}

});

$("#regqq").blur(function(){

if($("#regqq").val()=="")

{

$("#regqqtext").html("QQ不能为空!

");

}

});

$("#regemail").blur(function(){

if($("#regemail").val()=="")

{

$("#regemailtext").html("Email不能为空!

");

}

});

//鼠标进入输入框的效果

$("#reguser").focus(function(){

$("#regusertext").html("");

});

$("#regpassword").focus(function(){

$("#regpwtext").html("");

});

$("#regpassword1").focus(function(){

$("#regpw1text").html("");

});

$("#regtel").focus(function(){

$("#regteltext").html("");

});

$("#regqq").focus(function(){

$("#regqqtext").html("");

});

$("#regemail").focus(function(){

$("#regemailtext").html("");

});

//提交按钮按下后判断输入框是否为空

$("#register").click(function(){

varuser=$("#reguser").val();//得到user的值

varpassword=$("#regpassword").val();

varpassword1=$("#regpassword1").val();

vartel=$("#regtel").val();

varqq=$("#regqq").val();

varemail=$("#regemail").val();

if(user=="")

{

alert("用户名不能为空");

$("#reguser").focus();

returnfalse;//不返回false,就算没填进信息也会在数据库中自动创建信息

}

elseif(password=="")

{

alert("密码不能为空!

");

$("#regpassword").focus();

returnfalse;

}

elseif(password1=="")

{

alert("确认密码不能为空!

");

$("#regpassword1").focus();

returnfalse;

}

elseif(tel=="")

{

alert("联系电话不能为空!

");

$("#regtel").focus();

returnfalse;

}

elseif(qq=="")

{

alert("QQ不能为空!

");

$("#regqq").focus();

returnfalse;

}

elseif(email=="")

{

alert("Email不能为空!

");

$("#regemail").focus();

returnfalse;

}

});

});

php

include("config.php");

include("smarty_con.php");

@header('Content-type:

text/html;charset=GBK');

if(isset($_POST['register_y']))//用图片作为提交,需要加上_y或_x

{

$user=$_POST['reguser'];

$password=md5($_POST['regpassword']);

$sql=mysql_query("selectuserfromtb_userwhereuser='$user'");

$row=mysql_num_rows($sql);

if($row>=1)//判断用户是否已被注册(缺陷:

不能实时检测,需等待按下提交按钮才能检测)

{

echo"alert('用户已注册!

');";

}

else

{

$msql="insertintotb_user(id,user,password,tel,QQ,Email)"."values('','$user','$password','$_POST[regtel]','$_POST[regqq]','$_POST[regemail]')";

mysql_query($msql);

echo"alert('写入成功!

');";

}

}

$smarty->assign("title","RegisterPage");

$smarty->display("register.html");

>

 

用户注册页面效果:

鼠标离开必选框后提示

没填写信息就点击注册按钮的提示

重复用户名再次被注册提示

确认密码和输入密码不一致提示(当鼠标离开确认密码输入框后提示)

按下重写按钮后输入信息清空

按下注册按钮后数据库中添加了新用户

用户登录页面

验证码生成文件

php

session_start();

$img_width=50;

$img_height=25;

$authnum='';

$ychar="0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";

$list=explode(",",$ychar);

for($i=0;$i<4;$i++)

{

$randnum=rand(0,35);

$authnum.=$list[$randnum];

}

$_SESSION["login_check_number"]=$authnum;

$aimg=imagecreate($img_width,$img_height);

imagecolorallocate($aimg,255,255,255);

$black=imagecolorallocate($aimg,0,0,0);

for($i=1;$i<=100;$i++)

{

imagestring($aimg,1,mt_rand(1,$img_width),mt_rand(1,$img_height),"@",imagecolorallocate($aimg,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255)));

}

for($i=0;$i

{

imagestring($aimg,mt_rand(3,5),$i*$img_width/4+mt_rand(2,4),mt_rand(1,$img_height/4)+mt_rand(1,2),$authnum[$i],imagecolorallocate($aimg,mt_rand(0,100),mt_rand(0,150),mt_rand(0,200)));

}

imagerectangle($aimg,0,0,$img_width-1,$img_height-1,$black);

Header("Content-type:

image/PNG");

ImagePNG($aimg);

ImageDestroy($aimg);

>

效果:

登录页面样式

{$title}

用户登录


100px">

用户名:

160px;height:

24px;"/> 

#800000">*

#800000"id="logusertext">


100px">

密  码:

160px;height:

24px;"/> 

#800000">*

#800000"id="logpwtext">


100px">

验证码:

80px;height:

24px;"/>

#800000"id="logvertext">

165px">

pointer"id="refresh"border="0"src="verify.php"alt="验证码"/>

150px;">

17px"onclick="document.getElementById('refresh').src='verify.php?

t='+Math.random()">换一张

 

        

展开阅读全文

相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 工学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1