如何找出哪个父URL称为我的脚本?

I have created a page for a web banner under http://example.com/banner, I'm sending this link to publisher websites and pay them to run it.

However, some publishers run, some are not and I'd like to find which parent URL'S called for this page or where did the click come from. Generally, they are putting this URL in an iframe to serve it.

(Many pages doesn't pass referral parameter.)

I've tried different approaches with JS and PHP but as you might guess I'm getting http://example.com/banner as the parent URL.

Is there a way to know the parent URL from a different domain with PHP, JS or any other piece of code? I have a list of publishers but I also need to know which websites running the banner except for those sites.

To make it more clear here is a schema:

MY PAGE WITH BANNER > MY PUBLISHER WEBSITE > USER VISITING THE PUBLISHER

I don't want to get IP of the user visiting my publisher's website or my page's URL. I want to see URL of my publisher's website which is in between.

Since this is my web server I can read access logs, error logs etc. without issues.

I'm open to any suggestions.

Thanks!

You could try this, host a javascript file on your server.

Then they would place the script anywhere they want to put the banner:

<script src="//yoursite.com/banner.js"></script>

You could use params in that URL to then serve custom js.

Then fundamentally the code would look something like the following which injects the banner into the DOM where ever the script is placed. You get the sites URL from window.location.href and then send it as a param when requesting the image. (You could also use cookies etc)

<script>
  // inject an anchoring element
  document.write('<div class="banner_ad"></div>');
  // find it
  var parentDiv = document.getElementsByClassName("banner_ad");
  // create the img/banner, notice the site param
  var banner = document.createElement("img");
  banner.src = 'http://via.placeholder.com/350x150?site=' + encodeURI(window.location.href);

  // loop over the parent elements of each anchoring element
  for (var i = 0, len = parentDiv.length; i < len; i++) {
    // create the link
    var link = document.createElement('a');
    link.appendChild(banner);
    link.setAttribute('title', 'Ads by Foobar');
    link.setAttribute('href', 'http://example.com');
    // inject the link and img
    parentDiv[i].parentNode.appendChild(link);
  }
</script>

Then server-side, look for the $_GET['site'] param.

It's not foolproof, nothing is.

</div>