-3

Possible Duplicate:
Headers already sent by PHP

I know that I must use session_start() at the very top of the page, so the HTTP header can do his job before the HTTP body was started to send to the client. But it doesn't work well for me.

Here, I want to reset the session...

<?php 
ini_set( "display_errors", 0);  // Even without this it doesn't work, it's temporary to hide the problem
session_start();
$_SESSION = array();  // Clear the session
$_SESSION['state'] = "noConnection";
?>

<!DOCTYPE html>
<html> 
    <head>    // blah blah
Community
  • 1
  • 1
Pascal Boutin
  • 1,220
  • 2
  • 9
  • 22
  • 1
    Are there any stray spaces or newlines before the ` – Cranio Jun 16 '12 at 14:59
  • 2
    Also beware of anything after a closing `?>` tag in any includes. If you have a page that is nothing but PHP, I recommend leaving out the `?>` tag just to avoid this problem. – Brad Jun 16 '12 at 15:00
  • 1
    is this the complete script? Only possible error that I can think of if it is - you have some whitespace before the opening tag. If the file is in utf8 - check that it doesnt have a BOM (c/p the text to a new document and save in ansii) – karka91 Jun 16 '12 at 15:01
  • Use `session_unset()` and `error_reporting(0)`. – Steve Jun 16 '12 at 15:04

2 Answers2

2

The correct answer is to ensure there is nothing, not even spaces, or the UTF8 BOM character, before the first opening <?php tag.

The cheating answer is to set php.ini's output_buffering directive to On.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
0

Make sure there are no spaces before you open the <?php tag.

apaderno
  • 28,547
  • 16
  • 75
  • 90
ShayneStatzell
  • 122
  • 1
  • 11