php - headers already sent

I put error_reporting(E_ALL); in the top of a php program.

I get this:

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/fwsprinkler/public_html/ in /home/fwsprinkler/public_html/ on line 2

Warning: Cannot modify header information - headers already sent by (output started at /home/fwsprinkler/public_html/ in /home/fwsprinkler/public_html/ on line 53

Attached are 3 scripts; the top of the one being executes, part_dols.php & config.php (courtesy of an EE expert).

I fail to see the problem.

Richard KortsBusiness Owner / Chief DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
This is such a common issue that E-E has articles explaining it and showing the solutions.  Here ya go!
Dave BaldwinFixer of ProblemsCommented:
In your case (and I think we've gone over this before), session_start() belongs at the top of the main file just after error_reporting().  Putting it in an include file just invites problems like this.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Richard KortsBusiness Owner / Chief DeveloperAuthor Commented:
To all,

I took what Dave said & it seemed to work. I no longer got those messages.

However, what I'm trying to do, based on Ray's Remember me cookie concept, does not work.

See attached. This file is included in the main program. I want the remember me timeout set to 2 hours in the "real" case but I set it to 30 minutes for this test.

Note that if the session 'uid' is not set, & the cookie is NOT set, I am trying to redirect to index.php. It doesn't do that, it returns to the program that includes config.php.

In that (calling) program, I have the following:

include "config.php";
$cookie_name = "uuk";
if(!isset($_COOKIE['uuk'])) {
  echo 'Cookie with name "' . $cookie_name . '" does not exist...<br>';
} else {
  echo 'Cookie with name "' . $cookie_name . '" value is: ' . $_COOKIE[$cookie_name] . "<br>";

I waited over 30 minutes, refreshed the page. The cookie is gone, but it DOES not redirect.

Ray PaseurCommented:
Maybe just try running the script exactly as posted in the article.  Then once you have that working without any changes, you can start making changes -- but change only one thing at a time.  That way, when you hit the thing that causes the failure you will know it was the last change you made.  You can roll back to your last commit and see the difference that is causing the trouble.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.