Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/car/publ/testing/detail.php:1) in /home/car/publ/testing/detail.php on line 2

i'm getting this error.i dont have any empty whitespace in my code.

<?php
session_start();
?>
<html>
<head></head>
<body>
<form>
<?php
//code
?>
</form>
</body>
</html>

Dani AI

Generated

Most likely causes: a stray output before headers (whitespace or a UTF-8 BOM at the very start of the file), or some other file that runs before this one and sends output. That matches the two replies: (included files) and (auto-prepend settings). The goal is to locate which file/byte actually produced output and then remove it.

Quick diagnosis to find the origin

  • Use PHP’s diagnostic to get the exact file and line where output began: call headers_sent($file, $line) early (before you try to set headers) and display those values. That will tell whether the problem is the current file or something included earlier.
  • Check ini_get('auto_prepend_file') or run phpinfo() to see if a server-level file is prepended to every request.

How to fix once you know the culprit

  • If the offending file is the script itself and the error points at line 1, check for a UTF-8 BOM. In many editors the BOM is invisible; it looks like "nothing" but sends three bytes before PHP runs. Open the file in a hex-capable viewer or re-save it as “UTF-8 without BOM” in your editor.
  • Remove any accidental blank lines or spaces before the opening PHP tag. For pure-PHP files, omit the closing ?> tag to avoid trailing whitespace problems.
  • If an included or auto-prepend file is sending output, edit that file to remove output or move session/header logic before any output, or stop using auto-prepend if unnecessary.
  • As a temporary workaround you can enable output buffering (for example with ob_start() early), but that masks the root cause and is not ideal long-term.

Useful references: headers_sent() manual, session_start() manual, ob_start() manual, auto_prepend_file ini setting, and the Byte order mark (BOM).

Recommended Answers

All 2 Replies

Is this file perhaps included by another one ? Then maybe that one causes the error.

You may also want to check if you have an auto-prepend file set on your server.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.