PHP标题('位置:..')不在服务器上工作[重复]

This question already has an answer here:

I'm new to PHP. PHP header should redirect to specific page, but in my case PHP redirect is working on localhost fine but when I deploy the same code into server it is not working in the server. I also tried the below suggestions:

Which did't help in my case.

<?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';
    }
}


?>

Thanks in advance.

</div>

try to place the php code, at the beginning of the page, so that no output starts before,

    $host  = $_SERVER['HTTP_HOST'];
    $uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
    $extra = 'index.htm';
    $final_url = 'http://'.$host.$uri.'/'.$extra;
    header('Location:'.$final_url);

Replace code..