PDA

View Full Version : PHP "function.session-start" error.



loserWILL
20-07-2008, 10:51 PM
Error: Warning: session_start() [function.session-start (http://kolzy.com/xx/function.session-start)]: Cannot send session cookie - headers already sent by (output started at /home/kolzy/public_html/xx/index.php:7) in /home/kolzy/public_html/xx/config.php on line 15

Warning: session_start() [function.session-start (http://kolzy.com/xx/function.session-start)]: Cannot send session cache limiter - headers already sent (output started at /home/kolzy/public_html/xx/index.php:7) in /home/kolzy/public_html/xx/config.php on line 15

index.php

<?php

require_once("config.php");

if($logged['in'] === 0){

?>HTML<?php
}
else{
?>HTML<?php } ?>config.php - line 15

session_start();+rep

Florx
20-07-2008, 10:52 PM
The session_start(); needs to be before ANY HTML has been echoed onto the page.

Move it up to line 1.

Invent
20-07-2008, 10:56 PM
Jake, if you mean move it to line 1 in the index.php file then gb2/php.net/ :P.

I am *pretty* sure whitespace isn't counted as "HTML" after the php tag.

--

If you mean the config.php, thats fine ^_^

Florx
20-07-2008, 10:59 PM
I mean in the config file :P.

Invent
20-07-2008, 11:00 PM
Just making sure n_n

Florx
20-07-2008, 11:00 PM
That's okey dear :)

loserWILL
20-07-2008, 11:15 PM
So just under the <body> tag?

Florx
20-07-2008, 11:16 PM
session_start(); has to be before ANY html.

So no, it needs to be at the very top of the page.

iUnknown
20-07-2008, 11:18 PM
Just move it to the top of the config.php file - first line. There is your answer.

loserWILL
20-07-2008, 11:26 PM
You all sort of got the idea, fixed it though. +rep to all. (need to spread Simon)

Dentafrice
21-07-2008, 01:08 PM
Jake, if you mean move it to line 1 in the index.php file then gb2/php.net/ :P.

I am *pretty* sure whitespace isn't counted as "HTML" after the php tag.

--

If you mean the config.php, thats fine ^_^

It doesn't count just normal whitespace, ex:



<?php

session_start( );

// blabla
?>


Although it is a good practice, for any file that you are including, or just all-php, to prevent these errors:

Do not put the closing PHP operator into your program.



?>


if you leave it blank, it prevents whitespace.

Just FYI :P

Want to hide these adverts? Register an account for free!