0

Getting this stupid error over and over with absolutely no headers being sent other than this one over and over again ( prints 5 times each time page is ran )

Cannot modify header information - headers already sent by (output started at /home/xx/public_html/xx/index.php:1) in /home/xx/public_html/xx/index.php on line 1

My index.php:

<?php header('Content-Type:text/html; charset=UTF-8');
            require("load.php");?>
            <!DOCTYPE HTML>
            <html>
            <head>

My load.php:

<?php
define("ABS_PATH", $_SERVER['DOCUMENT_ROOT']);
include_once (ABS_PATH .'/assets/x/la.php');
require(ABS_PATH ."/assets/x/go.php");
///some more variables;?>

My la.php:

<?php
session_start();
header('Cache-control: private'); // IE 6 FIX

if(isSet($_GET['lang']))
{
$lang = $_GET['lang'];
}
/// more code?>

I have no idea what's going on.

EDIT: Found the issue. There was a freaking single space after my ?>. I removed it and voila, it is now fixed. Thanks obama

Mayron Mia
  • 33
  • 7
  • `header('Content-Type:text/html; charset=UTF-8');` Why is this line required at the top of your index.php page? – Akshay Aug 01 '15 at 10:32
  • Headers are sent when you output anything into a page. `session_Start` also should be at the top of a page. – u_mulder Aug 01 '15 at 10:33
  • 2
    You probably have some whitespace characters before or after your php-tags. If there is only PHP content in a file, remove the end-tag. And check that the file starts with – Karl Aug 01 '15 at 10:34
  • @Akshay Site is in german – Mayron Mia Aug 01 '15 at 10:40
  • Got it, check out my answer. – Akshay Aug 01 '15 at 10:40
  • @u_mulder yep, but the file is actually empty. Have no idea what's going on – Mayron Mia Aug 01 '15 at 10:40
  • A lot of PHP projects introduce a standard of no closing `?>` to avoid this problem. PHP will run just fine without it (so long s there's no non-php code in there), so it's safe to do and will help you avoid this stuff in the future. – Daniel Quinn Aug 01 '15 at 10:58
  • The definitive SO answer about this? [How to fix “Headers already sent” error in PHP](http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) – Ryan Vincent Aug 01 '15 at 11:16

2 Answers2

0

You must use session_start before any headers have been sent.

Put session_start; above header('Content-Type:text/html; charset=UTF-8');

rjdown
  • 9,162
  • 3
  • 32
  • 45
0

I see a whitespace here. Try this code.

<?php
session_start();
header('Content-Type:text/html; charset=UTF-8');
require("load.php");?>
<!DOCTYPE HTML>
<html>
<head>

Also, your session must be started before you send any headers.

Akshay
  • 2,244
  • 3
  • 15
  • 34