在 PHP 中拉取 GD 生成图像的远程 URL
我正在使用 PHP/GD 库生成图像,供人们放置在他们的网站上。类似于“点击计数器”服务。
我无法从加载按钮的页面中提取 URL。
以下内容仅显示我的网址,而不是他们的:
$_SERVER['SERVER_NAME'];
我需要在 Javascript 中提取域名吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SERVER_NAME 与您的服务器相对应。为了获取托管图像的服务器名称,可以通过几种不同的方式来完成。
您可以向图像调用 IE 添加获取字符串:img src="http://yousite.com/image.png?sitecode=32423",这是数据库中对放置图像的站点的引用。在我看来,这种方法是最可靠的。
和/或
您还应该能够使用 $_SERVER['HTTP_REFERRER'] 字符串来获取域及其来源的页面,并使用 parse_url 函数解析它。我不确定这种方法有多可靠,但一些测试可能有助于您了解它的可靠性。
希望有帮助。
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.
您是否正在尝试获取请求图像的页面的 URL?您可以让 IMG src 为您提供一些 GET 变量,例如:
然后,请求服务器让图像服务器知道他是谁。如果请求服务器有固定且唯一的 IP 地址,您也可以在此处使用它作为 KEY。
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:
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.