View Full Version : use PHP to display image on ebay?

05-17-2011, 10:37 AM

I currently display images on ebay with a simple image tag, that is hosted on my server,

I want to have it so that a range of IPs see a different image than someone outside of this particular IP range

i have tried...

$visitor = $_SERVER['REMOTE_ADDR'];
if (preg_match("/",$visitor)) {

print "<img src=http://example.com/SYDN.jpg width=30 height=15><br>";
} else {
print "<img src=http://example.com/MELB.jpg width=30 height=15><br>";

this seems to work in a browser, but when i use
<IMG SRC="http://example.com">
in ebay i just get the little box with a red x in it,

i know this is possible as i have used the following to display visitors flags in other auctions

<A HREF="http://www.hostip.info">
<IMG SRC="http://api.hostip.info/flag.php" BORDER="0" ALT="IP Address Lookup">

what have i done wrong???

05-17-2011, 03:57 PM
In order for a PHP script to "pose" as an image, you have to echo first an image header, and then crank out an image. And by cranking out an image, I mean an actual image, not an <img> tag.

For an example of what I'm talking about, see this page in the PHP manual (Example #1):


05-18-2011, 02:24 AM
If you don't need anything user-specific written to an image on the fly and only need to display various static images, you could use readfile():

$img = './images/image.png';

header( 'Content-type: image/png' );
header( 'Content-length: ' . filesize( $img ) );
header( 'Content-Disposition: attachment; filename="' . basename( $img ) . '"' );

readfile( $img );

You could then define the source file for $img using the visitor's IP address.