开发者

Pull Remote URL for GD Generated Image in PHP

开发者 https://www.devze.com 2023-01-08 02:49 出处:网络
I\'m generating images with PHP/GD Library for people to place on their websites. Similar to the \"hit counter\" services.

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 displa开发者_开发问答ys my url not theirs:

$_SERVER['SERVER_NAME'];

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


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.


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=<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.

0

精彩评论

暂无评论...
验证码 换一张
取 消