登陆页面php与 mysql
1连接数据库
1.依照mysql界面 地址 用户密码
2.仓库
3.创建连接对象
<?php
/*
依照mysql界面 地址 用户 密码
仓库
创建连接对象
*/
$addr='127.0.0.1';
$rootName='root';
$rootPwd='123456';
$db='db6';
$conn=new mysqli($addr,$rootName,$rootPwd,$db);
$conn->query('set names utf8');
?>
2数据库的调用
- 引入连接
- 接收参数
- 用户验证 查询
- 结果判断
- 签发通行证 session 先启动 写入
<?php
/*
1 引入连接
2 接收参数
3 用户验证 查询
4 结果判断
5 签发通行证 session 先启动 写入
*/
include'con0.php';
$usern=$_REQUEST['usern'];
$pwd=$_REQUEST['pwd'];
$url='../首页/music.php';
session_start();
$sql="select * from usern where usern='$usern' and pwd='$pwd'";
$res=$conn->query($sql);
if($res){
$num=mysqli_num_rows($res);
if($num>0){
echo '登陆成功';
Header("Location: $url");
$_SESSION['usern']=$usern;
$_SESSION['time']=time();
}else{echo'账号或密码不正确';
exit('登录失败!点击此处 <a href="login1.php">返回</a> 重试');
}
}else{
echo 'err';
}
$conn->close();
?>
3登陆页面
<?php error_reporting(0);?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>登录</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
.box {
width: 400px;
margin: auto;
text-align: center;
margin-top: 50px;
box-shadow: 0 0 2px gray;
background-color: rgb(245, 245, 245);
}
.box p {
margin: 6px 0;
height: 50px;
}
.top {
width: 400px;
height: 50px;
background-color: rgb(230, 0, 0);
box-shadow: 0 0 2px gray;
}
.top a {
display: block;
font-size: 24px;
color: white;
margin: 5px;
width: 80px;
height: 40px;
text-decoration: none;
}
.top a:hover {
background-color: rgb(200, 0, 0);
box-shadow: 0 0 2px gray;
}
.L1 {
/* background-color: green; */
width: 150px;
text-align: right;
font-size: 16pt;
}
.L2 input {
/* background-color: yellow; */
height: 30px;
}
.L2 {
font-size: 24px;
}
#sub {
width: 60px;
height: 40px;
}
</style>
</head>
<body>
<div class="box">
<div class="top">
<a href="../首页/music.php" style="float: left">游客</a>
<a href="register.html" style="float: right">注册</a>
<h1 style="text-align: center;color: white">登陆</h1>
</div>
<form action="login.php" method="post">
<table>
<tr>
<td class="L1">用户名:</td>
<td class="L2">
<input type="text" name="usern"/>
</td>
</tr>
<tr>
<td class="L1">密码:</td>
<td class="L2">
<input type="password" name="pwd"/>
</td>
</tr>
</table>
<!-- <p><input type="text" name="usern" placeholder="用户" style="margin-top: 20px;"/></p> -->
<!-- <p><input type="password" name="pwd" placeholder="密码" /></p> -->
<p><input type="submit" value="登陆" id="sub" /></p>
</form>
</div>
</body>
</html>
<?php
session_start();
$action='a';
if($_GET['action']=="logout"){
unset($_SESSION['usern']);
unset($_SESSION['pwd']);
// echo '注销登录成功!点击此处 <a href="login.html">登录</a>';
exit; }
?>