为什么在PHP 5.3中的exit()之后出现警告?

时间:2014-02-07 09:56:28

标签: php warnings exit

我有一个简单的登录检查:

function send_error($message) {
    header ( 'Content-Type: text/html; charset=utf-8' );
    header ( 'HTTP/1.0 406 Not acceptable' );
    echo $message;
    exit ();
}
session_start ();
if (! isset ( $_SESSION ["login"] ) || $_SESSION ["login"] === "" || ! isset ( $_SESSION ["type"] )) {
    send_error ( 'ERRORE: Devi prima aver eseguito il login per poter fare logout.' );
}

问题是如果用户没有登录,警告会出现在此部分之后的代码行。 为什么? exit();命令不应该停止执行代码吗?这是警告之一:

Warning: Cannot modify header information - headers already sent by (output started at /var/www/people/ltw1313/cgi-bin/verifica_login.php:11) in /var/www/people/ltw1313/cgi-bin/verifica_post.php on line 13

1 个答案:

答案 0 :(得分:0)

尝试在ob_flush();

之前撰写header ( 'Content-Type: text/html; charset=utf-8' );