<?php
session_start();
header('Content-type:text/html;charset=utf-8');
$code = $_POST["code"]; //驗證碼
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (empty($_POST['username '])){
echo "<script>alert('使用者名稱不能為空!');location.href='login.html';</script>";
# }else {
$username=$_POST['username'];
}
if (empty($_POST['password'])
## if (empty($_POST['password'])## if (empty($_POST['password'])
## if (empty($_POST['password'])## if (empty($_POST['password'])
## if (empty($_POST['password'])## if (empty($_POST['password'])
## if (empty($_POST['password'])## if
## echo "<script>alert('密碼不能為空!');location.href='login.html';</script>"; }else{
$password=$_POST['password'];
}
}
if($code != $_SESSION['authcode']) //判斷填寫的驗證碼是否與驗證碼PHP檔案產生的資訊符合
{
echo "<script type='text/javascript' >alert('驗證碼錯誤!');location='login.html';</script>";
}
$ mysqli = new mysqli('localhost', 'root', 'root', 'user');$result = $mysqli->query("SELECT password FROM user WHERE username = "."' $username'");$rs=$result->fetch_row();if (!empty($rs)){ if ($password != $rs[0]) { echo "<script>alert('密碼錯誤! ');location.href='login.html';</script>"; }else{ $expire=3600; $expire=3600; .gc_maxlifetime', $expire);//保存1小時 if (empty($_COOKIE['PHPSESSID'])) { #1 # session_start(); session_start(); session_start(); }else{ 可能) $expire);} if(isset($_SESSION['username'])){ header("location:### ); ###### $_SESSION['username']=$_POST['username'];###### }###### 登入 echo ); </script><br>";###
echo "你好!{$_SESSION['username']},歡迎回來!";
echo "<a href='logout.php'>註銷</a>" ;
}
}else{
echo "<script>alert('沒有此使用者!');location.href='login.html';< ;/script>";
}
?>
echo "<script type='text/javascript'>alert('驗證碼錯誤!');location='login.html';</script>";
#後加個return
寫程式碼不要用這麼多的if 沒有截斷