2

I have:

  • A page test.html in DOMAIN_A
  • A php script generator.php in DOMAIN_B

I have these needs:

  1. Include in test.html a javascript file generated by generator.php
  2. Generate this file according to the requestant domain (so generator.php has to know the requestant domain)
  3. The file test.html could be loaded in domains that I might not know

I have identified two ideas:


1) Using $_SERVER['HTTP_REFERER']

In test.html:

<script type="text/javascript" src="DOMAIN_B/generator.php">

In generator.php:

if( $_SERVER['HTTP_REFERER']=="DOMAIN_A" ) echo "<some js code>";

Unfortunally the variable $_SERVER['HTTP_REFERER'] is not reliable - source: How reliable is HTTP_REFERER?


2) Including the javascript passing the requestant domain dinamically

In test.html:

<script>
    var js = document.createElement("script");
    js.type = "text/javascript";
    js.src = "DOMAIN_B/generator.php?requestant_domain="+window.location.hostname;
    document.body.appendChild(js);
</script>

In generator.php:

echo "<some js code according to ".$_GET['requestant_domain'].">";

What do you think might be the best solution?

Do you have other ways to propose?

Community
  • 1
  • 1
Marco Panichi
  • 1,068
  • 1
  • 18
  • 31

0 Answers0