网页登录未重定向-php
我的登录页面的本地版本正常工作,但是联机版本不会重定向到管理页面。可能的原因是什么?下面是用于登录管理页面的代码。我没有收到任何错误(除非我输入了错误的用户/密码),但它不会重定向到管理页面 登录操作网页登录未重定向-php,php,mysqli,Php,Mysqli,我的登录页面的本地版本正常工作,但是联机版本不会重定向到管理页面。可能的原因是什么?下面是用于登录管理页面的代码。我没有收到任何错误(除非我输入了错误的用户/密码),但它不会重定向到管理页面 登录操作 <?php $username = ""; if (isset($_POST['login'])) { // Process the form // validations $required_fields = array("username", "password");
<?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']))
?>
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;
}
}
功能重定向到
function redirect_to($new_location) {
header("Location: " . $new_location);
exit;
}
我被告知以下错误:
[15-Oct-2017 17:03:32美国/纽约]PHP警告:无法修改
标头信息-标头已由发送(输出开始于
/home/qvthqtxu/public_html/christasite/includes/session.php:28)
/home/qvthqtxu/public_html/christasite/includes/functions.php联机
四,
这是开发人员的一个常见问题。所以最好使用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\" />";
echo”“;
什么是重定向到()
?您可能使用标题('location:admin.php')
而不是redirect_to()
redirect_to是一个包含标题的函数('location:admin.php');1) 检查物料清单。2) 使用会话启动
。3) 尝试使用标题('location:admin.php',true,301)代码>4)确保您的服务器数据库与您的本地数据库具有相同的管理员登录/密码条目(您是否上载了数据库?)1。检查每个页面上是否有session_start函数调用。2.退出();或会话写入关闭();使用头位置后的任何函数方法,即在您的情况下使用重定向到函数。3.检查重定向到函数下的会话值