我創建了一個登錄腳本,當用戶登錄時它應該將它們重定向到一個名爲users的目錄內的不同頁面,但它似乎不工作。下面是我的劇本我已經創造 -登錄腳本正在重定向
<?php
session_start();
$errors = [];
$username = isset($_POST['username']) ? $_POST['username'] : null;
$password = isset($_POST['password']) ? $_POST['password'] : null;
if(!empty($_POST)) {
if(empty($username)) {
$errors[] = "Please enter a username";
echo "<style type=\"text/css\"> #username { background-color:#F5A9A9;border:1px solid #DF0101; } </style>";
}
if(empty($password)) {
$errors[] = "Please enter a password";
echo "<style type=\"text/css\"> #password { background-color:#F5A9A9;border:1px solid #DF0101; } </style>";
} else {
if(empty($errors)) {
$dir = dirname("link/tooutside/wroot");
include($dir . '/directory/myconnect.php');
$salt = "thisismyhash";
$hashedpass = hash('sha512', $password . $salt);
$result = mysqli_query($conusers, "SELECT * FROM users WHERE username = '$username' AND password = '$hashedpass'");
if(mysqli_num_rows($result) == 1) {
$_SESSION['loggedin'] = 'true';
$_SESSION['username'] = $username;
header('Location: users/index.php');
} else {
$errors[] = "Your username or password is incorrect";
}
}
}
}
?>
現在,如果我用echo語句echo語句作品,但是當與重定向鏈接它不重定向我更換重定向代碼,它只是停留在index.php頁面上。
任何想法?
有什麼錯誤?嘗試使用'error_reporting(E_ALL)' – SheperdOfFire 2014-12-04 12:17:30