我是PHP的新手。 PHP标头应重定向到特定页面,但在我的情况下,PHP重定向正在对localhost进行正常工作,但是当我将相同的代码部署到服务器时,它无法在服务器中运行。我也尝试了以下建议:
在我的案例中哪个方面没有帮助。
<?php
include('../config/db.html');
if(!isset($_SESSION)){
session_start();
}
$msgsuccess = '';
if(!empty($_GET['msgsuccess'])){
$msgsuccess = $_GET['msgsuccess'];
}
if(isset($_POST) && !empty($_POST)){
if(!empty($_GET['url'])){
$url = $_GET['url'];
}
if(!empty($_POST['password'])){
$pass = md5($_POST['password']);
}
if(!empty($_POST['username'])){
$email = trim($_POST['username']);
}
$query = "select * from users where email = '$email' and password = '$pass'";
$exec_query = mysql_query($query);
$row = mysql_fetch_array($exec_query);
if(!empty($row)){
$_SESSION['adminfirstname'] = $row['firstname'];
$_SESSION['adminID'] = $row['id'];
$_SESSION['logged_in_admin'] = true;
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'index.htm';
header("Location: http://$host$uri/$extra");
die();
}
else{
$msgsuccess = 'INVALID CREDENTIALS!! PLEASE ENTER VALID EMAIL OR PASSWORD';
}
}
?>
提前致谢。
答案 0 :(得分:0)
尝试在页面开头放置php代码,以便之前没有输出,
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'index.htm';
$final_url = 'http://'.$host.$uri.'/'.$extra;
header('Location:'.$final_url);
替换代码..