1

I can't handle this error, please help me. It worked on my laptop but did not work on my desktop.

Why?

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at F:\xampp\htdocs\etest\index.php:1) in F:\xampp\htdocs\etest\common\header.php on line 3

The code:

<?php
ob_start();
session_start();
include("constants.php");
include("includes.php");
?>

Thanks for your kindness!

Charles
  • 50,943
  • 13
  • 104
  • 142
Freeman
  • 9,464
  • 7
  • 35
  • 58

9 Answers9

3

In general, when you see "headers already sent", it means that you are trying to do something that requires an HTTP header to be set, but you have already sent content to the client. When using HTTP, you have to send the headers, then the content comes after. If you've sent content, you've missed your opportunity to send headers.

Jim
  • 72,985
  • 14
  • 101
  • 108
3

the error was at F:\xampp\htdocs\etest\common\header.php on line 3 but output was already started at F:\xampp\htdocs\etest\index.php:1

I assume you posted the header.php, but your index.php either has whitespace before the <?php include() or outputs something other than a header on the first line.

the error is caused by line one of index.php, whatever is there. I'd guess whitespace.

lunixbochs
  • 21,757
  • 2
  • 39
  • 47
1

use_only_cookies=0 to use_only_cookies=1 in php.ini file

I encountered the same problem in xampp 7.0.1 and this fixed it. Read it here.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
kenn
  • 11
  • 1
  • 5
1

Start the session on top of the file.

direct afer the php tag when you make an echo or send some header before you get this errormessage.

<?php
session_start();
ob_start();
include("constants.php");
include("includes.php");
?>
René Höhle
  • 26,716
  • 22
  • 73
  • 82
  • 1
    you also can get this error if you have white spaces before the first php tag. – lszrh Mar 05 '11 at 18:03
  • see ob_start and the error message http://php.net/manual/en/function.ob-start.php – lunixbochs Mar 05 '11 at 18:05
  • 1
    I see you start it in header.php have you started it before? and make an include to header.php? So you have set this in index.php and include header.php in this file? @Mike Redford – René Höhle Mar 05 '11 at 18:09
1

Enable output buffering by configuration. This way it will start before anything else, so it certainly solves your problem. Although you should look at your code and find the cause of the present error, because it seems you do not fully understand your site yet.

After enabling output buffering by configuration, you no longer need to call ob_start() manually.

Create a file called .htaccess with this content:

php_flag output_buffering on

... or add this line to your php.ini:

output_buffering = On
vbence
  • 20,084
  • 9
  • 69
  • 118
  • 1
    good alternate, though your php.ini entry should simply be `output_buffering = On` and the PHP docs recommend setting to a number instead of just On http://us3.php.net/manual/en/outcontrol.configuration.php#ini.output-buffering – lunixbochs Mar 05 '11 at 18:18
  • I deleted the "set" part. Setting the limit is somewhat tricky because we don't enough about the website of the poster IMHO. – vbence Mar 05 '11 at 18:36
0

Yes start the session on top of the file amd make sure you do not have a space before

<?php

Plus you can call session_start(); only one time

rtacconi
  • 14,317
  • 20
  • 66
  • 84
0

session_start() must be called before there is ANY other output. The error is telling you that output started on index.php line 1. The call to session_start() must be placed before that.

Mark Eirich
  • 10,016
  • 2
  • 25
  • 27
0

Put this code inside includes.php

ob_start();
session_start();

And remove the same code from every other page. Also make sure that in your files there is no whitespace before the initial

(specifically you are getting the error because something is wrong on the first line of index.php not of header.php)

tacone
  • 11,371
  • 8
  • 43
  • 60
0

I was getting this even when I had it at the top of the file.

Problem INVISIBLE UTF8 CHARACTER

Solution Was to delete the file and make a new one starting with <?php and then copy everything after the php into the new one. (Don't copy the beginning of the file).

Kevin Upton
  • 3,336
  • 2
  • 21
  • 24