资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

php登录模板带数据库 php登录界面模板

怎么用php写一个简单的登陆页面,要连上数据库

数据库是SQLserver

我们提供的服务有:成都网站建设、网站建设、微信公众号开发、网站优化、网站认证、上虞ssl等。为上千企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的上虞网站制作公司

?

if(isset($_GET['username']))

{

session_start();

$errormsg = "";

$input['username'] = strtolower(trim($_GET['username']));

if($errormsg == "")

{

include("db_link.php");//你自己SQL数据库所在路径

$sql = "select

user_id,

username,

status

from guestbook

where username = '".$input['username']."' and status = 1";

$result = mysql_query($sql, $link) or die('Query database failed');

$num = mysql_num_rows($result);

if($num 1)

{

$errormsg = "用户名不正确,请重新登录!";

}

else

{

$row = mysql_fetch_array($result);

if($row['username'] == $input['username'])

{

$_SESSION['s_user_id'] = $row['user_id'];

$_SESSION['s_username'] = $row['username'];

$_SESSION['s_status'] = $row['status'];

$_SESSION['time_last_load'] = time();

?

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

html

head

title管理员登录/title

style

button,input{font-size:12px;padding-top:2px;font-family : Arial, Helvetica, sans-serif;}

a:link:{color:#666666;}

a:visited:{color:#666666;}

a:hover:{color:#000000}

/style

/head

body style="font-size: 12px;"

table width="280" border="0" cellspacing="0" cellpadding="0" align="center" style="font-size: 12px;border:1px solid #639ECE;"

trtd height="10"/td/tr

trtd height="40" align="center"登录成功!/td/tr

trtd height="10"/td/tr

trtd height="22" align="right" bgcolor="#EFFBFF"a href="javascript:void(null);" onclick="window.close();"关闭窗口/a /td/tr

/table

/body

/html

?

}

else

{

$errormsg = "用户名不正确,请重新登录!";

}

}

}

if($errormsg "")

{

?

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

html

head

title管理员登录/title

style

button,input{font-size:12px;padding-top:2px;}

/style

/head

body style="font-size: 12px;"

table width="280" border="0" cellspacing="0" cellpadding="5" align="center" style="font-size: 12px;border:1px solid #639ECE;"

trtd height="10" colspan="2"/td/tr

form action="userlogin.php"

tr

td width="60" align="right"用户名:/td

td width="220"input type="text" name="username" value="?=$input['username']?"/td

/tr

tr

td/td

td align="center" input type="submit" value=" 登录 "/td

/tr

/form

tr

td height="10" colspan="2"/td

/tr

tr

td height="22" colspan="2" bgcolor="#EFFBFF"?=$errormsg?/td

/tr

/table

/body

/html

?

}

}

else

{

?

!--登录页面--

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

html

head

title管理员登录/title

style

button,input{

font-size:12px;

padding-top:2px;

}

/style

/head

body

table width="280" border="0" cellspacing="0" cellpadding="5" align="center" style="font-size: 12px;border:1px solid #639ECE;"

trtd height="10" colspan="2"/td/tr

form action="userlogin.php"

tr

td width="60" align="right"用户名:/td

td width="220"input type="text" name="username"/td

/tr

tr

td/td

td align="center" input type="submit" value=" 登录 "/td

/tr

/form

trtd height="10" colspan="2"/td/tr

/table

/body

/html

?

}

?

PHP写个一个正常的登录页面,用mysqli的方式连接数据库,HTML也面用from的表单格式

?php

//注册页

$username = $_POST['username'];

$password = $_POST['password'];

$password1 = $_POST['password1'];

$email = $_POST['mail'];

//判断用户名

if(empty($username)){

exit('用户名不能为空');

}

//判断密码

if(empty($password)){

exit('密码不能为空');

}

if($password == $password1){

}else{

exit('两次密码不相等');

}  

//判断邮箱格式    

$yx = '/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/';    

if(preg_match($yx,$email)){

}else{

exit('邮箱格式错误');

//连接数据库

$link = mysqli_connect('localhost','root','') or die('失败');

//设置字符集,选择数据库表;

mysqli_select_db($link,"test")or die('选择数据表失败');

mysqli_set_charset($link,'utf8')or die('设置字符集失败');

//写入注册表

$reg = "insert into user(name,password) value('$username',md5('$password'))";

$reg1 = "insert into userdetail(name,emali,nickname) value('{$username}','{$email}','{$username}')";

//释放结果集;

//提交sql语句

$result1 = mysqli_query($link,$reg1);

$result = mysqli_query($link,$reg);

if(mysqli_affected_rows($link)){

if(mysqli_affected_rows($link) 0){

mysqli_close($link);

die('用户添加成功!');

}else{

mysqli_close($link);

die('用户名重复,请修改后重新添加');

}

}else{

mysqli_close($link);

die('用户添加失败,请重新添加');

}

//关闭退出

mysqli_close($link) or exit('no');

这是那过程 写的 ,

php写一个登陆界面并且保存到数据库,实现1天免登陆,求源码

login.php

!doctype html public "-//W3C//dtd html 4.01 transitional//en" ""

html

head

title New Document /title

meta http-equiv="content-type" content="text/html; charset=utf-8"

meta name="Generator" content="EditPlus"

meta name="Author" content=""

meta name="Keywords" content=""

meta name="Description" content=""

/head

body

form name="form1" method="post" action="confirm.php"

p用户名:input type="text" name="user"/p

p密码:input type="password" name="pwd"/p

pinput type="submit" name="b1"/p

/form

/body

/html

用php做个登陆界面,代码要怎么写,用户名和密码在数据库中,怎么关联呢。

你可以做一个简单的例如你只有用户名和密码即可那么你先在数据库(以mysql为例)中建表例如叫做user 字段为 id name pass分别是编号、用户名、密码长度分别是int(8) a_t(自动编号) 主键,varchar(50) ,varchar(50) 你可以添加一个测试数据 例如 1,admin,admin//说明密码这里不说加密的问题,用明文实现 登录页面的代码:login.phphtmlheadtitle用户登录/title/headbodyform action="checklogin.php" name="loginform" method="post"用户名:input name="name" type="text"br密 码:input name="password" type="password"brinput value="登录" type="submit"br/form/body/html checklogin.php代码(检测登录): $name=$_POST[name];$pass=$_POST[password];session_start();//这个可以维持登录状态,可以参照session的使用

//登录检查函数 function login_state($uid,$user_shell){ $sql="SELECT * FROM `user` WHERE `name`='$name'";

$query=@mysql_query($sql) or die(mysql_error());

$us=is_array($row=@mysql_fetch_array($query));

$user_shell=$us ? $user_shell==$row[password]:FALSE;

if($user_shell){ echo "scriptalert('登录成功');/script";

return $row;

}else{

echo "scriptalert('您暂时不能浏览该页面,请先登录');location.href='login.php';/script";

} }login_state($name,$password);?

希望可以帮到您,如果还有问题可以联系2458285853


网页标题:php登录模板带数据库 php登录界面模板
网站URL:http://cdkjz.cn/article/ddgdppg.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220