Warning: Cannot modify header information - headers already sent by [duplicate]
When i try run this file i am getting this error.
<?php
$im = imagecreatetruecolor(100, 100);
// sets background to red
$red = imagecolorallocate($im, 255, 0, 0);
imagefill($im, 0, 0, $red);
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp1\htdocs\check\2.php:1) in C:\xampp1\htdocs\check\2.php on line 7
�PNG ��� IHDR���n������V,����PLTE����[an����fIDAT�c`�`fx���`Ǡ����41����˖ݒ�q�@;{á0� �i
If that is the complete script, and there really is nothing shown in front of the opening <?php
tag (your editor may have a 'visible white space' option that would show anything), another thing it may be is the file has been saved as UTF8, and has a 'BOM' as the first couple of characters in the file. Resaving it as plain text (maybe 'ANSI') may improve matters.
Another possibility is that a file is being prepended before the script is being run. That may have output in it, or trailing content after a closing php tag (my advice - don't have a closing PHP tag unless specifically required).
Move the header('Content-type: image/png');
to the top of the script won't hurt, unless there really is something being output before the opening tag.
Alister said pretty everything about what could causes that error, but there is one more thing. PHP might throw some error/warning/notice. Remove the header and check whether there is no errors.
Use this given code...i hope u will not find any error
精彩评论