in reply to Conditional statement problem

Okay, without a bit more information, I'm unsure exactly could be causing the problem here, but I have a few ideas ...

The program is designed to be called from a page by an image tag.

Is this to mean that the CGI script is called in the following fashion?

<img src="/cgi-bin/myscript.cgi" />

If so, then this is where your problem is - Your browser will be expecting the result of the script to be of content image/gif or alike, whereas your script is returning text/html (check the CGI documentation on the header method for details).

If indeed, this is how you are calling your script, you have two options as far as I can see:

  1. Assuming your web server is configured to support SSI, change the referencing of the CGI script to thus:

    <!--#include virtual="/cgi-bin/myscript.cgi" -->

    The result being the incorporation of the text/html content returned by your current script into the HTML document.

  2. Change your script so that the returned content is of type image/gif or alike based on the type of image returned, similar to the following *untested* code:

    print header( -cookie => $to_set, -type => "image/gif" ); eval { open (FH, $image); print <FH>; close (FH); } || die $!;

 

Ooohhh, Rob no beer function well without!

Replies are listed 'Best First'.
Re: Re: Conditional statement problem
by Anonymous Monk on Nov 14, 2001 at 20:27 UTC
    Yes, Rob it was the image causing the problem although I'm still not clear why as the image did get returned if the cookie was set. But I swiped the following subroutine code to print the image and now the program works fine. Thanks.
    my $image = 'logo.gif'; open(IMAGE, "<$image") or die "cannot open image file: $!"; my $no_bytes = (stat ($image))[7]; print "Content-type: image/gif\n"; print "Content-length: $no_bytes\n"; print "Pragma: no-cache\n\n"; print <IMAGE>; close(IMAGE) or die "cannot close image file: $!";