用html和php实现登录功能

使用静态网页语言html和服务器端脚本语言PHP实现登陆功能;

浏览器通过POST方法与服务器进行请求-响应(HTTP方法:GET-从指定的资源请求数据;POST-向指定的资源提交要被处理的数据);

服务器获取表单提交的数据,并对数据库用户表进行查询,如果能成功匹配,则允许用户进行登陆,否则不能登录。

数据库


根目录


访问地址

http://localhost/login/login.php

页面





login.php

<!doctype html>
<html>

<head>
<meta charset="utf-8">
<title>登录</title>
</head>

<body>
<form method="POST" action="login_check.php">
	<table border="1" align="center"width="420" height="370">
    	<tr align="center">
        	<td valign="center">
				<table border="0" width="400" height="350">
    				<tr>
						<td colspan="2"><img src="login_top.jpg"/></td>
					</tr>
    				<tr height="40">
						<td width="140" align="right" style="font-size:12px">用户名:</td>
            			<td><input name="uname" type="text" /></td>
					</tr>
     				<tr height="40">
						<td width="140" align="right" style="font-size:12px">密码:</td>
       	    			<td><input name="pwd" type="password" /></td>
					</tr>	
       	 			<tr height="40">
						<td colspan="2" align="center"><input type="submit" value="登录" /></td>
					</tr>	
        			<tr height="40">
						<td colspan="2" align="center" style="font-size:10px" bgcolor="#51A37C">By:Liu 2015.9.28</td>
					</tr>
    			</table>
        	</td>
        </tr>
    </table>>
</form>
</body>

</html>
</pre><span style="color:#009900;">login_check.php</span><p></p><p><pre name="code" class="php"><!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>


<body>
<?php


header("content-type:text/html;charset=utf-8");


//连接数据库
$dblink=mysql_connect("localhost","root","root") or die("数据库连接失败");


//设置字符串编码
mysql_query("set names utf8");


//选择数据库
mysql_select_db("user");


//获取表单数据。
$uname=$_POST['uname'];
$pwd=$_POST['pwd'];


//可以对密码进行md5加密。
//$pwd=md5($pwd); 


$sql="select * from user where username='{$uname}'";  
$rs=mysql_query($sql);<span style="white-space:pre">	</span>//执行sql查询
$num=mysql_num_rows($rs);<span style="white-space:pre">	</span>//获取记录数


if($num)<span style="white-space:pre">	</span>//用户存在;
{ 
<span style="white-space:pre">	</span>$row=mysql_fetch_array($rs);


<span style="white-space:pre">	</span>if($pwd===$row['password'])<span style="white-space:pre">	</span>//密码正确。
    { 
    <span style="white-space:pre">	</span>echo "登陆成功,正在为你跳转至后台页面";
    <span style="white-space:pre">	</span>//header("location:index.html");
    }
<span style="white-space:pre">	</span>else
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>echo "密码不正确";
<span style="white-space:pre">		</span>echo "<a href='login.php'>返回登陆页面</a>";
<span style="white-space:pre">	</span>} 
}
else
{
<span style="white-space:pre">	</span>echo '用户不存在';
<span style="white-space:pre">	</span>echo "<a href='login.php'>返回登陆页面</a>";
}


?>
</body>


</html>



  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值