1

here's the error code :

Cannot send session cookie - headers already sent by (output started at
C:\xampp\htdocs\log\New folder (4)\New folder (2)\iskono\forum.php:5) in 
C:\xampp\htdocs\log\New folder (4)\New folder (2)\iskono\forum.php on line 244

Warning: session_start() [function.session-start]: Cannot send session cache limiter - 
headers already sent (output started at C:\xampp\htdocs\log\New folder (4)\New folder 
(2)\iskono\forum.php:5) in C:\xampp\htdocs\log\New folder (4)\New folder 
(2)\iskono\forum.php on line 244 

line 244 is the require code

<? require("forum/index.php"); ?>

how solve this error?

stealthyninja
  • 10,343
  • 11
  • 51
  • 59
Iskono Morto
  • 79
  • 1
  • 7

6 Answers6

5

You need to put your session_start call before any output (HTML, for example), is sent. So put it above your doctype declaration and make sure there is no whitespace before. For example:

<?php
    session_start();
?>
<!DOCTYPE html>
<html>
...
Alex Turpin
  • 46,743
  • 23
  • 113
  • 145
3

You have obviously sent some data before calling session_start(), this must be called at first place!

Right

<?php
session_start();
echo "hi man :) "; // this is right

Wrong

<?php
echo "hi man :( ";  //this is wrong
session_start();
Marek Sebera
  • 39,650
  • 37
  • 158
  • 244
2

Since no one else has mentioned it yet: If you are encoding your files (NOT output of your files, the files themselves) in UTF, make sure you do so without a byte order mark (UTF-8 without BOM).

Adding the BOM at the beginning of the file can cause this error, since it counts as output.

Additionally, you can use output buffering to solve any other issue relating to 'headers already sent' errors. This causes no output to be sent until you explicitly say 'send output' with ob_flush() or ob_end_flush().

Jeff Lambert
  • 24,395
  • 4
  • 69
  • 96
1

You have done one of the following:

  • Called echo, print or some other function that causes output on line 5.]
  • include or required a file that has caused output to be sent. Check all you included files for leading/trailing whitespace before/after the <?php ?> tags.
  • Done something else that has cause an error message to be written to output on line 5.

What is on line 5?

DaveRandom
  • 87,921
  • 11
  • 154
  • 174
1

Make sure you aren't sending any characters to the browser before the session starts.

It looks like you're sending something on line 5 of forum.php.

The could be due to an echo, print or because you're sending text directly from your script:

<?php
  some code....
?>
text sent to the browser
<?php
  more code.
  session_start();
?>

Ensure that the session starts early by putting session_start(); at the beginning of your script.

Many others have had similar problems with sessions. Take a look at the PHP manual regarding session_start() at http://php.net/manual/en/function.session-start.php for session problems, solutions and tips.

Stacey Richards
  • 6,536
  • 7
  • 38
  • 40
1

In php, A header can be send before any other output is sent. If you have sent any output before header, your header will generate an error. (even a space before the

Sourabh
  • 1,757
  • 6
  • 21
  • 43