Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

How to fix “Headers already sent” error in PHP language ?

When running my script, I am getting several errors like this:

Warning: Cannot modify header information - headers already sent by (output started at /some/file.php:12) in /some/file.php on line 23

The lines mentioned in the error messages contain header() and setcookie() calls.

What could be the reason for this? And how to fix it?
by

2 Answers

Kajalsi45d
I got this mistake often previously, and I am sure all PHP software engineer got this blunder in any event once previously.

Solution 1

This blunder may have been brought about by the clear spaces before the beginning of the record or after the finish of the file. These clear spaces ought not to be here.

echo "your code here";

?>
THERE SHOULD BE NO BLANK SPACES HERE

Solution 2:
If this isn't your case, at that point use ob_start to yield buffering:

<?php
ob_start();

// code

ob_end_flush();
?>
MounikaDasa
This type of problem is caused when you use header after you write in your page. I assume you code might look like ::

<html>
<head>
<title> title </title>
.........
</head>

<body>
.....
<?php
header() // checking some header
?>
.....
</body>
</html>
If so, use header() before html or any kind of echo or writing code. But this is not correct solutions. You can use ob_start. This is the best solution. check this

Login / Signup to Answer the Question.