0

I have a simple login check like this:

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.' );
}

The problem is that warnings show up for lines of code that come after this part if the user has not done login. Why? Shouldn't exit(); command stop code execution? This is one of the warnings:

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
Ariel
  • 1,222
  • 2
  • 14
  • 25
  • I suggest you read the documentation about sending headers in php. And about output buffers. – arkascha Feb 07 '14 at 10:00
  • possible duplicate of [How to fix "Headers already sent" error in PHP](http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) – 웃웃웃웃웃 Feb 07 '14 at 10:01

1 Answers1

0

Try writing ob_flush(); before header ( 'Content-Type: text/html; charset=utf-8' );