Salve a tutti,

perché con questo script gli header non funzionano?
Codice PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>LOGIN</title>
</head>

<body>



  <?php 
include ("config.php"); 
// mostro un eventuale messaggio
    
if(isset($_GET['msg'])) {
        echo 
'[b]'.htmlentities($_GET['msg']).'[/b]

'
;
    }


if (isset(
$_POST['invia'])) {

    
$username $_POST['user'];
    
$password $_POST['pwd'];
    
    
$username trim(mysql_real_escape_string($username));
    
$password trim(mysql_real_escape_string($password));
    
    if(
get_magic_quotes_gpc()) {
        
$nome      stripslashes($nome);
        
$password  stripslashes($password);
    }
    
    
    if (!
$username || !$password) {
    
    echo 
"dovete inserire dei dati";
     }else{
     
    
$query "SELECT id_user FROM users_sito WHERE username ='$username' AND password='$password'";
    
$result mysql_query ($query,$db) or die (mysql_error()); 
    
$righe mysql_num_rows($result);
    
    if (
$righe 0) {
    
$messaggio urlencode("autentificazione effettuata");
    
header("location: $_SERVER[PHP_SELF]?msg=$messaggio");
        exit; 
    
    }else{
        
$messaggio urlencode("autentificazione non effettuata");
    
header("location: $_SERVER[PHP_SELF]?msg=$messaggio");
        exit; 
    
}
}

}



?>
</p>


LOGIN </p>
<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  <label>user
  <input type="text" name="user" id="user" />
  </label>
  <label>password
  <input type="text" name="pwd" id="pwd" />
  </label>
  <label>
  <input type="submit" name="invia" id="invia" value="Invia" />
  </label>
</form>



</body>
</html>
Questione di spazi?