前端 html 用form 指向后台 LOGIN.PHP
用户登录
后台 login.php
//登录
if(!isset($_POST['submit'])){
exit('非法访问!');
}
$username = htmlspecialchars($_POST['username']);
$password = MD5($_POST['password']);
//包含数据库连接文件
include('conn.php');
//检测用户名及密码是否正确
$check_query = mysql_query("select * from user_list where username='$username' and password='$password' limit 1");
if($result = mysql_fetch_array($check_query)){
//登录成功
session_start();
$_SESSION['username'] = $username;
$_SESSION['userid'] = $result['userid'];
echo $username,' 欢迎你!进入 用户中心
';
echo '点击此处 注销 登录!
';
exit;
} else {
exit('登录失败!点击此处 返回 重试');
}
//注销登录
if($_GET['action'] == "logout"){
unset($_SESSION['userid']);
unset($_SESSION['username']);
echo '注销登录成功!点击此处 登录';
exit;
}
?>