首页 > 编程知识 正文

php用户登录模板(php用户注册登录)

时间:2023-12-06 16:47:14 阅读:312676 作者:QEMN

本文目录一览:

  • 1、PHP做一个用户登录页面
  • 2、用php制作用户登录认证网页(cookie方法和session方法)
  • 3、用php制作用户登录认证网页

PHP做一个用户登录页面

index.html登录页面代码如下:

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""

html xmlns=""

head

meta http-equiv="Content-Type" content="text/html; charset=gb2312" /

title登录示例/title

/head

body

form id="forms" name="forms" method="post" action="loginchk.php"

用户名:input type="text" id="uname" name="uname" value=""/br/

密码:input type="password" id="upass" name="upass" value=""/br/

input type="submit" id="loginbtn" value="立即登录"/

input type="reset" id="resetbtn" value="重新填写"/

/form

/body

/html

loginchk.php 的PHP程序代码如下:

?php

$uname=trim($_REQUEST["uname"]);

$upass=trim($_REQUEST["upass"]);

if($uname=="admin"$upass=="admin")

{

echo "登录成功";

}

else

{

echo "登录失败,a href='index.html'重新登录/a";

}

?

以上只是一个简单示例,真正的开始,需要考到很多因素,比如说登录前有效性检查,加入登录验证码,程序需要连接数据库进行用户匹配等。

希望对你有帮助 。

如果使用数据库进行进行匹配的话,PHP程序可以这样改进一下。

?php

$uname=trim($_REQUEST["uname"]);

$upass=trim($_REQUEST["upass"]);

$con = mysql_connect("localhost","root","root");

mysql_select_db("dbname", $con);

$result = mysql_query("select * from dusers where uname='$uname' and upass='$upass'");

$rs = mysql_fetch_array($result);

if($rs)

{

echo "登录成功";

}

else

{

echo "登录失败,a href='index.html'重新登录/a";

}

?

不过你需要连接到你自己的指定的数据库和数据表。

用php制作用户登录认证网页(cookie方法和session方法)

?php

//用户登陆

if(isset($_POST["sub"]))

{

$conn=mysql_connect("localhost","root","root")or die("数据库服务器连接错误".mysql_error());

mysql_select_db("hu",$conn);

$mysql="SELECT id FROM user

WHERE name = '$_POST[name]'

AND PASSWORD = '$_POST[password]'

";

$result=mysql_query($mysql,$conn);

$isrows=mysql_num_rows($result);

if ($isrows0)

{

$row=mysql_fetch_assoc($result);

$time=time()+3600;//cookie保存的时间

SETCOOKIE("name",$_POST[name],$time);

SETCOOKIE("uid",$row[id],$time);

SETCOOKIE("islogin",true,$time);

HEADER("Location: index.php");//登陆成功,你要跳转的页面

}

else

{

echo "用户密码有误";

}

}

?

html

titlecookie test/title

body

form action="login.php" method="post"

table align="center" border="1" width="250"

captionh1用户登录/h1/caption

tr

th 用户名/th

td

input type="text" name="name"

/td

/tr

tr

th密 码/th

td

input type="password" name="password"

/td

/tr

tr

td colspan="2" align="center"

input type="submit" name="sub" value="登录"

/td

/tr

/table

/form

/body

/html

用php制作用户登录认证网页

将用户名和密码提交到指定的页面,如checkform.php,然后在该页面中以传来的用户名和密码为条件,在数据库中查找,如果有记录的话,成功登陆,如果没有,就说明没有该用户,活着用户名错误

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。