views:

88

answers:

2

I'm generating images with PHP/GD Library for people to place on their websites. Similar to the "hit counter" services.

I am not able to pull the URL from the page that the button is loaded on.

The following only displays my url not theirs:

$_SERVER['SERVER_NAME'];

Am I going to need to pull the domain in Javascript?

+10  A: 

SERVER_NAME corresponds with your server. In order to grab the server name that the image is hosted on can be done a couple different ways.

You can add a get string to the image call IE: img src="http://yousite.com/image.png?sitecode=32423" which is a reference in your database to the site you put the image on. This method would be the most reliable imo.

And/Or

You should also be able to use the $_SERVER['HTTP_REFERRER'] string to get the domain and the page it came from, and parse it with the parse_url function. I am not sure how reliable this method would be, but some testing may be beneficial for you to know how reliable it is.

Hope that helps.

Brad F Jacobs
Thanks, HTTP_REFERER is working for now, not sure how reliable it will be.
Billy Shall
@Billy it's pretty reliable. It can easily be faked or turned off on client side, but requires *users* to change their browsers. People embedding the images on their sites can't prevent a referer from being sent.
Pekka
A: 

Are you trying to get the URL of the page that is requesting the image? You could have the IMG src provide you with some GET variables, like:

‘ <img src="http://yourimageserver.com/render.php?requestURL=&lt;php? Echo $_SERVER['SERVER_NAME']; ?>" /> ‘

The requesting server then lets the image server know who he is then. If the requesting servers will have fixed and unique IP addresses, you can use that as the KEY here as well.

Evan
I was trying to avoid having variables in the url, only "/images/image.png". If the HTTP_REFERRER proves to be unreliable I might have to add them, Thanks!
Billy Shall