AdamGold AdamGold - 3 months ago 11
PHP Question

PHP inside img src

Trying to see what actions can be performed with a PHP script that is being called via an image src like so:

<img src="http://example.com/script.php" />


Now, I have tried to include the PHP header() function in script.php:

<?php
header("Location: http://example.com");


I have also tried to echo an image url expecting the img to display it, which it didn't:

<?php
echo 'http://example.com/image.png';


Are there any ways of doing such things with a PHP script that is being called in the img src attribute?

Answer

Are there any ways of doing such things with a PHP script that is being called in the img src attribute?

No. A resource that is used as a src for an img tag needs to output image data, nothing else.

There are some exceptions, eg. a header("location: ....") redirect, but the redirect needs to point to another valid image resource, not a web site as you show in your example.

Comments