0
votes

I'm using < img src="logo.php" > to call a php page that writes some stuff to the database before displaying the actual gif image. Let's call this VERSION 1

On any given page, the code looks like this:

<a href="http://www.abc.com">
<img alt="Hi" src="http://www.abc.com/logo.php"/></a>

Then, logo.php looks like this:

// first update a database table with some relevant info

// then, output the logo image

header("Content-Type: image/gif");
echo file_get_contents("/path/to/image/logo.gif");

It's working great, (thanks to the answers i rec'd here: Stack Question Answered

Now, I'm trying to create a second option that does the exact same thing, except it displays some html as well as the image. Let's call this VERSION 2

On any given page, the code looks like this:

<a href="http://www.abc.com">
<img alt="Hi" src="http://www.abc.com/logo_html.php"/></a>

I want this other file, "logo_html.php" to output something like this

<p>Hello World</p>
<p>Some More html</p>
<img alt="Hi" src="http://www.abc.com/logo.gif"/>

I tried to change the 'echo file_get_contents' file to a php file with a simple < p>Hello World< /p>, but nothing shows up (just the X that you get when the browser can't find the image.

If this is my "logo_html.php" file, and I change it to this, then put some text in myfile.php, I also get no results.

header("Content-Type: image/gif");
echo file_get_contents("/path/to/file/myfile.php");

What do I need to change in my logo_html.php file to be able to bring up and display the image, plus some additional html?

Thanks in advance as always!

3
"logo_html.php" only can has abc.com/logo.gifJefferson

3 Answers

2
votes

You cannot output anything but the image binary contents. src attribute of the image tag accepts the address to the binary image contents, not to the html.

So the final answer: you cannot do that.

0
votes

You can't do that. If this was possible and you would link to my image, I would give you and image and a script tag that would steal your customers' cookies ;).

0
votes

You should use <iframe>. Image elements can't contain anything else than images – the browser would think the code is part of the image data but because it doesn't match the mime type (GIF images must start with GIF89a or sth like that) it would think it's broken.

Also file_get_contents("/path/to/file/myfile.php") returns content of the php file. You probably want to include it.