October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Fix PHP “Headers Already Sent” and `session_start()` Errors

A PHP “headers already sent” warning points to output that began before a session or header operation. Use the reported file and line to find and fix it.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A PHP “headers already sent” warning means output began before PHP tried to send or change HTTP headers. If it appears at session_start(), find the earlier output, then move session initialization ahead of page rendering and remove the unintended output.

What “headers already sent” means

HTTP headers are sent before the response body. A session start may need to send a session cookie or other headers, and PHP cannot add those headers after the response header block has been sent. As the PHP manual explains, “You can’t add any more header lines using the header() function once the header block has already been sent.”

As an Amazon Associate I earn from qualifying purchases.

The warning may say “Cannot modify header information – headers already sent by” or, for a session, “session_start(): Cannot send session cache limiter – headers already sent.” The wording describes the failed header operation; the location named after “output started at” is usually the more useful clue.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read the two locations in the warning

A typical message points to both where output started and where PHP later tried to send headers. For example:

Warning: Cannot modify header information - headers already sent by (output started at /path/file.php:34) in /path/other.php on line 42

  • /path/file.php:34: Inspect this first. It identifies where PHP began output.
  • /path/other.php:42: This is where the later header operation—such as session_start() or header()—could not proceed.

Trace what was loaded before that first location, too: included files can produce output before the file containing the session call runs. WordPress’s troubleshooting guidance also recommends interpreting the message this way.

Find what produced the earlier output

At the reported starting file and line, check for visible output as well as characters that are easy to miss. Common causes include:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Whitespace or a blank line before an opening <?php tag, or after a closing ?> tag.
  • A UTF-8 byte order mark (BOM) at the start of a PHP file.
  • HTML outside PHP code, or echo and print calls that run before session or header logic.
  • An earlier warning, notice, or error printed into the response.

These are among the causes described in the PHP.earth troubleshooting guide. If the line itself seems harmless, inspect the files it includes and the code that runs before it.

Fix the cause and put header-dependent work first

Move session_start(), redirects, cookie operations, and other work that sends or changes headers ahead of templates and response content. Then remove or correct the earlier output that triggered the warning. The PHP manual’s session_start documentation covers starting a session; the key for this error is that the call must run before output has been sent.

  1. Copy the complete warning and note both file-and-line locations.
  2. Inspect the “output started at” location, including whitespace, encoding, output statements, earlier PHP messages, and included files.
  3. Move session or other header-dependent calls before HTML, templates, and debug output.
  4. Remove the unintended output, then repeat the request that produced the warning.

Use headers_sent() when the source is unclear

PHP’s headers_sent() function can check whether headers have already been sent and, when available, return the filename and line where output began:

if (headers_sent($filename, $line)) {
  error_log("Output started at $filename:$line");
}

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

This is a diagnostic aid, not a replacement for fixing the ordering problem. PHP notes that the filename may be empty if output began before the PHP file ran, such as from a startup error.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When output buffering is—and is not—a fix

Output buffering can defer output from being sent immediately. It can be appropriate when an application deliberately relies on buffering, but adding ob_start() everywhere can conceal premature output and make behavior depend on buffering configuration. Unless buffering is an intentional part of the design, fix the source of the output and the order of operations instead.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.