English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

This code shows a random number inside a picture:
Header ("Content-type: image/png");
$img_handle = imageCreateFromPNG("Secure.png");
$color = ImageColorAllocate ($img_handle, 100, 100, 100);
$jo = "6767fjddms8";
$random_digit=rand(00000000000000,99999999999999);
ImageString ($img_handle, 12, 32, 7, "$random_digit", $color);
ImagePng ($img_handle);
ImageDestroy ($img_handle);
?>

This works fine. But i want this picture to be shown on a webpage as well as other things so i put that code into a .inc file. Then i included that file in another page on my site but it read the header from the inc file and said "ERROR - Headed already sent.
How do i stop this from happening?
So it just shows the picture along with ohter things on the page?

2006-12-03 02:49:46 · 4 answers · asked by peter s 1 in Computers & Internet Programming & Design

4 answers

You can't use header() after any HTML element. You also can't use header() after you've used echo. Sounds like your include happens after an HTML element or an echo.

You don't neeed to add the content-type statement to the page if you want to create an image. PHP's built-in imaging functions will create the proper type of image without you specifying it.

Try removing the header() command altogether. Also, try converting your code to a function that you call as you need to display dynamic images.

2006-12-03 02:56:20 · answer #1 · answered by Anonymous · 0 0

You can't send the header if you've already sent body information. This includes any white space liek a spoace at the beginning of your file. The very first thing should be include ('file.inc'); in the file that calls the include. If there is a space before it, or any other data you will get that error.

2006-12-03 02:52:44 · answer #2 · answered by traciatim 3 · 0 0

Including your code for an image in code that generates HTML doesn't include your image in the HTML. Instead, in the code that you would like to have the image in, output an tag. So, if the above code was in image.php, and you want it included in mypage.php, then mypage.php would be something like...

print("");
print("");
print("");
?>

2006-12-03 02:57:34 · answer #3 · answered by rons_brain 2 · 0 0

Also, make sure you dont have any whitespace.

2006-12-03 03:41:03 · answer #4 · answered by arus.geo 7 · 0 0

fedest.com, questions and answers