记录:前端用户登陆验证

登陆页面login.php

<?php session_start(); error_reporting(0); require_once ('include.php'); //未解决的问题:能匹配用户名,可是不能匹配密码。 // 导致结果:知道用户名,任意密码都能登陆 ?>

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>登陆</title> </head> <body> <form method="post" action="login.php"> <table> <tr> <td>用户名:</td> <td><input type="text" name="user"> </td> </tr> <tr> <td>密码:</td> <td><input type="password" name="passwd"> </td> </tr> <tr> <td><input type="submit" name="sub" value="提交"></td> </tr> </table> </form> </body> </html> <?php echo "<br>"; if (isset($_POST['sub'])) { $user = $_POST['user']; $passwd = md5($_POST['passwd']);

	checkLogin($user,$passwd);
}

?>

验证函数:login // 判断用户登陆 function checkLogin($user,$passwd) {

	echo "你输入的的账号是".$user.".<br>正在与数据库进行比对......";
            //选择user表中的user,passwd与提交过来的的$user,$passwd进行对比
	$sql = "select * from user where `user` = '{$user}' and `passwd` ='$passwd' limit 1 ";
	$query = mysql_query($sql);
            //使用mysql_fetch_assoc进行数据集检索
	$result = mysql_fetch_assoc($query);

	if(!$result){
		echo "比对失败".mysql_error();
	}else{
		echo "登陆成功";
	}

}

转载于:https://my.oschina.net/kopa/blog/323862

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值