ubantu下php和myql实现登陆功能并且在主页显示用户名

阅读: 评论:0

ubantu下php和myql实现登陆功能并且在主页显示用户名

ubantu下php和myql实现登陆功能并且在主页显示用户名

直接上代码:

登陆表单【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小时内删除。

标签:用户名   功能   主页   ubantu   php
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23