Graph not showing properly [duplicate]
I have created a graph using php. The script is working correctly when it is run separately, but when I put it with other code, instead of a graph some strange characters show, the error is :
Warning: Cannot modify header information - headers already se开发者_Python百科nt by (output started at C:\xampp\htdocs\samplesite\header.php:99) in C:\xampp\htdocs\samplesite\Pets\Dogs\Afgan Hound.php on line 161
header.php has been included at the start of page.
Your header.php
script sends some output, possibly even just whitespace before headers are called in your main script. If your AfganHound.php
script attempts to store a cookie via setcookie()
, or calls session_start()
after header.php
has been included, the action will fail with the error you received.
If header.php
produces output (and we suspect it does), it must be included after your main script sets cookies or calls session_start()
According to comments, the main script calls header("Content-type:image/png");
to output an image.
This is the source of the problem. You cannot output both HTML and an image in the same script execution. Your HTML page (the one with the menus created by header.php
should contain an <img>
tag which calls the graphing script as its src
attribute. When the browser loads the HTML page and requests this <img>
, instead of being served a static png image, it calls the PHP script which produces the graph and delivers it back to the browser as an image. The browser is unaware that it has called a PHP script, and just treats it like any other image to display.
<img src='/path/to/graph_generator_script.php' alt='what the image contains' />
Then the graph generation script must not produce any output except for the image data (no HTML), with its associated header:
header("Content-type:image/png");
精彩评论