--- Wade Smart <[EMAIL PROTECTED]> wrote:

> Marc Boncz wrote:
> 
> 03232008 1415 GMT-6
> 
> Thanks for that code Marc. Before I saw your post I found another script 
> so I tried that one and two others and none of them are working. It must 
> be that I do not understand how to use them.
> 
> <?php
>       ini_set('display_errors', 1);
>       error_reporting(E_ALL);
>       header("Content-Type:image/png");
>       $img_handle = imagecreatefrompng("bannerboy.png");
>       $color = imagecolorallocate($img_handle, 100, 100, 100);
>       $ip = $_SERVER("REMOTE_ADDR");
>       imagestring($img_handle, 3, 10, 9, "Wade's IP: $ip", $color);
>       imagepng($img_handle);
>       imagedestroy($img_handle);
> ?>
> 
> and titled it ip-addr.php
> 
> and then on another page I called it
> 
> <img src="ip-addr.php" />
> 
> but I have no image and show no errors.
> 
> Wade

When using the header() function, it is often necessary to include the carriage
return and linefeeds.  Capitalization and spacing are sometimes an issue.

header("Content-Type:image/png");

should be:

header("Content-type: image/png\r\n\r\n");

Also, the way you have $_SERVER uses parens instead of brackets.  With parens
PHP will think it is a function and it will not work:

$ip = $_SERVER("REMOTE_ADDR");

should be:

$ip = $_SERVER["REMOTE_ADDR"];

The way you had it, it could throw an undefined function error or simply put an
empty string in $ip.

I guess you have your source image ("bannerboy.png") in the same directory as
your PHP script and the image-calling page?

If your script does throw an error, you will not get any useful output. 
Firefox might say the image cannot be displayed if you go to the script
directly.  Your error settings will send output to the browser (if thrown) and
the header() function will not work.  Perhaps this is OK.  You will get the
"headers already sent" error if something is displayed.

Naturally, the opening PHP tag must be on the first line and start at the first
character position to ensure that the header() function will work when it is
error free.

James

Reply via email to