直接上代码:
登陆表单【login.php】
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ".dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body><br/><br/><br/><br/><br/><br/><br/><form action="logcheck.php" method="post"><div class="sign-ipt f-l"><p>用户名:</p><input type="text" name="id" placeholder="ID" /><p>密码:</p><input type="password" name="pwd" placeholder="密码" /><br /><button class="slig-btn">登录</button><p>没有账号?请<a href="register.php">注册</a></p></div></form></body>
</html>
登陆后台检测【logcheck.php】
<?phpsession_start();header("Content-type: text/html; charset=utf-8");$username = $_POST['id'];$password = $_POST['pwd'];$conn = new mysqli('localhost','led','123456','db_cexu');if ($conn->connect_error){echo '数据库连接失败!';exit(0);}else{if ($username == ''){echo '<script>alert("请输入用户名!");(-1);</script>';exit(0);}if ($password == ''){echo '<script>alert("请输入密码!");(-1);</script>';exit(0);}$sql = "select id,pwd,name from cexu_data where id = '$username' ";$result = $conn->query($sql);$number = mysqli_num_rows($result);$row = mysqli_fetch_array($result);
// echo $row['name'];
/*while($row = mysqli_fetch_array($result)){echo "<br/>";echo $row['id'];echo "<br/>";echo $row['pwd'];echo "<br/>";echo $row['name'];}
*/ if ($number) {$_SESSION['username'] = $row['name'];echo "<script>window.location.href='index.php'</script>";} else {echo '<script>alert("用户名或密码错误!");(-1);</script>';}}
?>
主页【index.php】
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ".dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body><?php
session_start();
echo $_SESSION['username'];
echo "<br/>";
?>
<h1> 欢迎来到在线测序网站 </h1></body>
</html>
输出结果:
----------------------------------分割线------------------------------------------------
参考:
本文发布于:2024-01-30 06:41:24,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170656808619919.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |