Mike
Mike

Reputation: 2735

Call an external PHP script on a website without using PHP

My issue is following: My Partner's have websites and I want that partners can include a script from my server that dynamically generates a link and an image.

i.e. myscript.php (on my server) generates following output:

<a href="http://www.myserver.com/apples.php?12345">
<img src="http://www.myserver.com/images/12345.png" />
</a>

I don't want my partners to be bothered with any php scripting, hence the best solution for now is to supply them with an iframe, where the src is the link to my script on my server that generates the output above.

However I clearly don't have any control over my partner's website and i.e. opening a lightbox out of the iframe certainly won't work.

Because of that I tried a different approach. I used Ajax to dynamically load my script, however this also doesn't work due to ajax security features (you cannot call an external script via ajax - only if you do a php workaround).

So basically, my question is: Is there any good solution to call my script on my server on the partner's website and display the generated code on my partner's website without the use of php?

Upvotes: 2

Views: 3917

Answers (3)

jonipalosaari
jonipalosaari

Reputation: 153

Could you make it with javascript file which replace/creates that anchor where ever you put the javascript link.

picture.js:

$('#image').ready(function(){
  var image = 'http://host/url/to/image.jpg';
  $('#image').load(image);
});

on you partners site:

<div id="image">
 <script type="text/javascript" src="http://yourhost/picture.js"></script>
</div>

I don't know if it possible, but.. :) and this needs jQuery. And im slow.

Upvotes: 0

Sietse
Sietse

Reputation: 717

Make a PHP file, like

<?php
$url = "http://www.myserver.com/apples.php?12345";
$img = "http://www.myserver.com/images/12345.png";
echo "document.getElementById('divthing').innerHTML = '<a href=\"" . $url . "\"><img src=\"" . $img . "\" /></a> '";
?>

Your partner's page would be like:

<html>
<body>
Hey, check this site out: <div id="divthing"></div>
<script type="text/javascript" src="http://yoursite.com/script.php"></script>
</body>
</html>

(I know, not really clean code (innerHTML etc), but you should get the idea :))

Upvotes: 1

Quentin
Quentin

Reputation: 944170

Have your PHP generate JavaScript (don't forget the content-type header). Then they can include it with a <script> element.

Upvotes: 2

Related Questions