1.登录界面
登录界面实现账号、密码匹配数据库登录。登陆成功则跳转到首页page.html。
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>demo1</title> </head> <body> <form method ="POST" action="demo1.php"> <center><h1>登录</h1> 账号:<input type="text" name="username"></input> <br> 密码:<input type="password" name="passwd"></input> <br> <br> <input type="submit" value="登录"></input> </form> </body> </html>
<?php $host="127.0.0.1"; $id="root"; $pwd="123456"; $database="test"; $conn=mysqli_connect($host,$id,$pwd,$database); if($conn==true) //连接成功 { echo "connect success<br>"; $username=$_POST['username']; $password=$_POST['passwd']; $sql="select * from users where username='".$username."' and password='".$password."'"; $result=mysqli_query($conn,$sql); if($result==false) echo "false"; else { $items=mysqli_fetch_all($result); if(count($items)>=1) { echo "usename and password is right<br>"; $times=time()+30*60; session_start(); $_SESSION['name']="zhangsan"; //setcookie("name","qzsqzs",$times); header("Location:<http://127.0.0.1/index.php>"); } else { echo "usename and password is false<br>"; header("refresh:2;url=./demo1.html"); } } } else echo "connect false<br>"; ?>
退出链接到登录界面demo1.html。
Quit.php
<?php header("refresh:1;url=./demo1.html"); exit(); ?>