有条件地向远程站点提供徽标 [英] Conditionally Serving a Logo To A Remote Site

查看:43
本文介绍了有条件地向远程站点提供徽标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为特定的一群人创建一个代码片段,这些人有权在他们的网站上盖上我们的印章.这个想法起初看起来很简单,直到我尝试通过不同的网站来实现它进行测试.

I am attempting to create a code snippet for a specific group of people that have earned the right to put our seal on their website. The idea seemed simple enough at first until I tried to implement it through a different website for testing.

基本上我希望用户有一个代码片段,如:

basically i want the user to have a code snippet like:

//include jquery for post
<script type="text/javascript" language="javascript" src="http://www.mysite.com/jquery.js"></script>

<script language="javascript">
    $.post("http://www.mysite.com/test.php", {requesting_id:"12345", requesting_address:window.location.host}, function(data){
    document.write(data);
  });
</script>

test.php 根据 sql 数据库检查传递的变量.如果他们传递的 ID 与请求文件的网址匹配,并且我们同意继续在他们的页面上提供我们的徽标(真/假),则它会返回图像.

test.php checks the passed variables against an sql db. If the id they pass matches the web address asking for the file and if we have agreed to continue serving our logo to their page (true/false), it returns the image.

只要所有文件都存在于我的服务器上,这就会很好地工作.问题似乎与 php 文件似乎不在我的服务器上运行,而是在请求服务器上运行的事实有关,因此查询没有运行.

This works great as long as all of the files live on my server. It appears that the problem has to do with the fact that the php file seems to run not on my server but on the requesting server so the query doesn't run.

有没有一种简单的方法可以做到这一点?我花了几个小时寻找一种方法,但我没有想法.

Is there a simple way of doing this? I have spent hours searching for a method and I am out of ideas.

感谢您的帮助!

推荐答案

我不会为此使用 javascript,也绝对不需要所有这些网站都包含 jquery.

I would not use javascript for that and definitely not require all these sites to include jquery.

如果您使用的是 php,最简单的方法是从 php 文件提供图像.图像看起来像:

If you are using php, the easiest thing is to serve an image from a php file. The image would look like:

<img src="http://yoursite.com/image.php?request_id=XXXX">

然后你制作了一个基于 request_id 提供图像的 php 脚本.

and you make a php script that serves an image based on the request_id.

您必须在 php 中从您的服务器读取图像并使用 header("Content-type: image/jpeg")(如果是 jpeg...).

You would have to read an image from your server in php and serve it with a header("Content-type: image/jpeg") (in case of a jpeg...).

如果您在变量中有图像,则输出(对于 jpeg...)将简单地类似于:

If you have an image in a variable, the output (for a jpeg...) would simply be something like:

header("Content-type: image/jpeg");
imagejpeg ($image);

这篇关于有条件地向远程站点提供徽标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆