-1

I am facing a problem in one of my current project. Just sharing if anybody had experience on this type of problem. While i try to use the below script :

header('Content-Type: image/jpeg');

the below error shows:

Warning: Cannot modify header information - headers already sent by (output started at /location/test.php:1) in /location/controller/Captcha.php on line 89

I have used ob_clean(); before the header('Content-Type: image/jpeg'); function to clean buffer. But not wroking. I am also check for any output or newline in php files, but found nothing.

Can anybody give me a solution please?

Shah Alom
  • 1,031
  • 1
  • 14
  • 26

2 Answers2

1

Basically this type of problem occur when any space or new line exist out of the php tags or anything printed before the header function. but in the problem in my project problem is all of my php file is saved with ANSI encode except the test.php file. the test.php file was saved with utf-8 encoding.

while the captcha.php file tried to access the test.php that automatically print some special character (i don't know why).

Problem of my project solved when i convert the encoding to ANSI of test.php.

Thanks to Fred for his replies.

Shah Alom
  • 1,031
  • 1
  • 14
  • 26
  • You're welcome Shah. Then my answer was the correct one then. Could you accept my answer by clicking on the checkmark under the arrows? That will mark your question as being "answered". Cheers. – Funk Forty Niner Aug 19 '13 at 02:36
0

Without seeing full code, chances are you have whitespace besides or above your <?php tag, or HTML or some other type of "output", possibly even a byte order mark.

<?php

echo "Correct";
// or vvv, but not with echo
// header("Location: http://www.example.com/");

?>

Examples of what are considered as "output" (before headers):

(space)
(space) <?php

echo "Incorrect";
header("Location: http://www.example.com/");

?>

<div align="center">Text</div> <!-- HTML -->
<!-- comment tags also considered as output -->
<?php

echo "Incorrect";
header("Location: http://www.example.com/");

?>

(byte order mark) // aka BOM which is invisible but still present
<?php

echo "Incorrect";
header("Location: http://www.example.com/");

?>

For more information on the header() function, visit the PHP.net Website:

Community
  • 1
  • 1
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • I have checked for any output or newline or white space in php files, but found nothing. – Shah Alom Aug 17 '13 at 16:21
  • @ShahAlom Then chances are you have a byte order mark then. Many things can be considered as output before headers. You need to find what it is that is causing this. Possibly an include, a function. Without seeing your entire code and structure, is hard to tell. And if there is nothing (space, HTML) before your headers, then it's a byte order mark (BOM). Byte order marks are considered as output also. – Funk Forty Niner Aug 17 '13 at 16:24
  • 1
    @ShahAlom You would need to save/encode your file(s) as UTF-8 without BOM. Download a copy of Notepad++ if you don't already have it. You can get it here => **http://notepad-plus-plus.org/** – Funk Forty Niner Aug 17 '13 at 16:25
  • @ShahAlom Check **all** your files, **even if "one"** of the files involved/included has any output before the opening ` – Funk Forty Niner Aug 17 '13 at 16:34