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 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.
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.
Thanks for the help!
I would not use javascript for that and definitely not require all these sites to include jquery.
If you are using php, the easiest thing is to serve an image from a php file. The image would look like:
and you make a php script that serves an image based on the request_id.
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…).If you have an image in a variable, the output (for a jpeg…) would simply be something like: