我的登录页面的本地版本正常工作,但是在线版本不会重定向到管理页面。 可能的原因是什么? 以下是用于登录管理页面的代码。 我没有收到任何错误(除非我输入了错误的用户/密码),但它不会重定向到管理页面。
登录操作
<?php
$username = "";
if (isset($_POST['login'])) {
// Process the form
// validations
$required_fields = array("username", "password");
validate_presences($required_fields);
if (empty($errors)) {
// Attempt Login
$username = $_POST["username"];
$password = $_POST["password"];
$found_admin = attempt_login($username, $password);
if ($found_admin) {
// Success
// Mark user as logged in
$_SESSION["admin_id"] = $found_admin["id"];
$_SESSION["username"] = $found_admin["username"];
redirect_to ('admin.php');
} else {
// Failure
$_SESSION["message"] = "Username/password not found.";
}
}
} else {
// This is probably a GET request
} // end: if (isset($_POST['submit']))
?>
attempt_login功能
function attempt_login($username, $password) {
$admin = find_admin_by_username($username);
if ($admin) {
// found admin, now check password
if (password_check($password, $admin["password"])) {
// password matches
return $admin;
} else {
// password does not match
return false;
}
} else {
// admin not found
return false;
}
}
功能redirect_to
function redirect_to($new_location) {
header("Location: " . $new_location);
exit;
}
我收到此错误:
[15-Oct-2017 17:03:32 美国/New_York] PHP 警告:无法修改 标头信息 - 标头已由 (输出开始于 /home/qvthqtxu/public_html/christasite/include/session.php:28) in /home/qvthqtxu/public_html/christasite/include/functions.php on online 四
这是开发人员的常见问题。所以最好使用 HTML 重定向。
<meta http-equiv="refresh" content="0; url=http://example.com/" />
<meta http-equiv="refresh" content="0; url=./admin.php" />
<meta http-equiv="refresh" content="0; url=./admin/" />
不要忘记嵌入如下 php 代码。
echo "<meta http-equiv="refresh" content="0; url=./admin.php" />";