session_start() problem

Struggling with the headers already sent problem. Here is the start of my index.php

<?php
ob_start();
session_start();
?>

I have tried every fix found in the forums with no luck. When I run the code from phpDesigner, this is the error:
PHP Warning: session_start(): Cannot send session cookie - headers already sent in C:\Development\PHP_Projects\BrothersNetLogger\index.php on line 3 PHP Stack trace: PHP 1. {main}()

When I run the code from the hosting company’s server, no error, all works fine.

Any suggestions are welcome. Need to fix the php.ini for Designer?

Hard to tell with little code you have, but headers already sent is one of the trickiest for people new to php.

No code can be executed before headers are sent. The simplest thing to do is surround the header redirection code (‘Location: example.php’); with an if statement if you are unsure if any code is going to be executed before or be absolutely make sure no code is going to executed before headers being sent.It becomes second nature once you get into developing with php for some time and soon that kind of error will be rare. Though from time to time I still run into, but usually it’s a simple fix now. :wink: Though if I had to guess, I would say that you’re starting sessions way to late, simple fix to me would to put session_start() at the very begging of your php code.

Thanks for your response.

Well, the code I showed starts at line 1 of the index.php There is no code preceding it.
And the problem only occurs when running it from phpDesigner, not the hosting server.
Can you explain what you mean by surround the header redirection code with an if statement?

Sponsor our Newsletter | Privacy Policy | Terms of Service