<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>歡迎來到XXX網</h1>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<span>郵箱:<input type="text" name="user_email"></span>
<span>密碼:<input type="text" name="user_pass"></span>
<span> <input type="submit" name ='submit' value="登陸"></span>
<input type="button" onClick="location.href='register.php'" value="注冊" />
</form>
<?php
//開始登錄
if(!isset($_POST['submit'])){exit('非法訪問!');}
$user_email = htmlspecialchars($_POST['user_email']);
$user_pass = htmlspecialchars($_POST['user_pass']);
//包含數據庫連接文件
include('conn.php');
//檢測用戶名及密碼是否正確
$check_query = mysql_query("select user_id,user_nickname from users where user_email='$user_email' and user_pass='$user_pass' limit 1");
if($result = mysql_fetch_array($check_query))
{
//登錄成功
@ session_start();
$_SESSION['user_id'] = $result['user_id'];
$_SESSION['user_email'] = $user_email;
echo $result['user_nickname'].',歡迎你!---<a href="my.php">用戶中心</a> ';
echo '<a href="index.php?action=logout">注銷</a><br />';
exit;
}
//登陸失敗
else {exit('登錄失敗!點擊此處 <a href="javascript:history.back(-1);">返回</a> 重試');}
//注銷登錄
if ( $_GET['action'] == "logout" && isset($_SESSION['user_id']) )
{
echo '注銷成功!點擊此處 <a href="login.html">登錄</a>';
unset($_SESSION['user_id']);
unset($_SESSION['user_email']);
exit;
}
?>
</body>
</html>
if(!isset($_POST['submit'])){exit('非法訪問!');}
你不是post訪問這個頁面並且沒有傳遞sumit參數,上面的代碼就是true當然會自行die代碼
判斷代碼公用的時候注意要增加op參數什麼的,判斷是相關的操作在判斷值是否存在什麼的,而不是直接判斷值,要不就出現你這種錯誤了