使用用户名,密码登录,正确可以登入,错误返回登录界面
1.建立登录界面
<body> <h1>登录</h1> <form action="chuli.php" method="post"> <div>用户名:<input type="text" name="uid" /></div> <div>密码:<input type="text" name="pwd" /></div> <div><input type="submit" value="登录" /></div> </form> </body>
2.chuli.php页面:
<?php session_start(); $uid = $_POST["uid"]; $pwd = $_POST["pwd"]; include("../DBDA.class.php");$db = new DBDA();$sql = "select count(*) from users where uid =‘{$uid}‘ and pwd = ‘{$pwd}‘"; $r = $db->StrQuery($sql); if($r==1){ $uid = $_SESSION["uid"]; header("location:main.php");}else{ header("location:log.php");}
3.main.php页面:
<body> session_start(); //判断用户名是否为空,防止漏洞 if(empty($_SESSION["uid"])) { header("location:log.php"); } echo $_SESSION["uid"]; </body>
时间: 2024-10-10 03:59:57