serg66
serg66

Reputation: 1148

Control existence and appearence of a banner on different sites

We have a banner. This banner is located on different sites-partners. We don't have admin access to these sites. The banner has to be on each site. But how to control this? It can be done manually, but it would be great if there were ways to do it automatically (especially when the list of the sites is huge). The banner has to be visible. It means that it's not enough to just check HTML-code on each of the sites. JavaScript and CSS have to be taken to consideration because one can easily hide the banner using these instruments. I think it's a common task, but I couldn't find anything on the web. Any thoughts and links would be appreciated.

Upvotes: 1

Views: 167

Answers (1)

Alma Do
Alma Do

Reputation: 37365

In short: no way. That means - you can not be sure that banner will 100% appear for each visitor of your partner's web-site.

Why it is impossible?

  • First, such thing as AdBlock - yes, even if all is going fine, most people don't want to see ads, so they are free to use any tools to disable it. Important note: AdBlock will check request URI before sending request & retrieving content from server, so it's working scheme is 'prevent before loading', not 'load & then hide'. That means - if your banner will be added to blacklist - no request for it will be done from client.
  • Ok, let us suppose that we've left all client-side stuff alone and dealing only with partner's web-site. I.e. from there we're assuming that client do not have 'evil' things that prevents your banner from appearing:

What can we do?

At first glance, using PHP there's HTTP_REFERER field in $_SERVER environment variable. Using it you can check which web-site requested your banner. Let it be an image, so you can easily perform your check:

function checkReferer($referer)
{
   //this could also be retrieved from config or DB:
   $clients = [
      //client name with available referrers:
      'Lorem Ipsum' => ['page1_address.php', 'page2_address.php']
   ];
   //get client:
   $client = key(array_filter($clients, function($referrers) use ($referer)
   {
      return in_array($referer, $referrers);
   }));
   //perform some DB updates, which set state of $client
}

//some stuff
checkReferer($_SERVER['HTTP_REFERER']);

//sending image:
$image = '/path/to/image.png';
header('Content-Type: image/png');
readfile($image);
exit();

How it works? It will retrieve web-page address, from which your banner.php script was requested. Not all clients will send this header (I mean HTTP_REFERER - it's non-mandatory), but in most cases it will contain valid address. In this case you may rely on this since it's your partner interest that you will get that properly (because you're checking them). So: when a visitor will open your partner's web-site, your script will be requested. Example:

<!-- somewhere on partner's side in HTML: -->
<img src='http://your-site.com/banner.php'/>

Alternative: you may want to have even more solid condition. Then you'll need to assign some unique code for each partner and tell to it that code. Your image will look like:

<img src='http://your-site.com/banner.php?code=codeOfThisPartner'/>

-and in PHP you'll just have 1:1 relationship between partners and their codes:

function checkPartner($code)
{
   //this could also be retrieved from config or DB:
   $clients = [
      'codeOfThisPartner' => 'Lorem Ipsum',
      //...
   ];
   //get client:
   $client = $clients[$code];
   //perform some DB updates, which set state of $client
}
//the rest is the same, code will be in $_GET['code'], obviously

What's wrong with this?

If we're supposing that client's browser is not disabling ads, then method above will work only for those cases, when partner's web-site is not hiding your banner. As you've mentioned, there could be javascript that hides your banner. They could, for example, perform a call of your script and then hide it in hidden block. So - this is a way to filter only good partners.

What other ways can be suggested?

You can try to request your partner's pages with cURL, for example. Since you've mentioned that you'll have many partner's pages with your banner, you'll better to use curl_multi_* to increase speed of your queries. Algorithm will be:

  • Request partner's web-site
  • Check if your banner exist in HTML code. You can, for example, ask your partner for strict form of placing your banner (may be even some partner's code inside banner's link)

What about JavaScript?

Common answer: nothing. There are million ways to spoil your banner. There are also million ways to hide that fact, that something in html/javascript is spoiling your banner (.eval() in javascript, yes). And there's no way you can check that automatically unless you'll write full browser emulation with javascript engine & html renderer (and even there it will be hard to answer a question 'will that banner appear on the right place of screen'). If you don't trust your partner, then, unfortunately, you'll have to check that site manually - i.e. you'll 100% sure only with checking by your own eyes.

Side note

You should also keep in mind that different web-browsers would handle markup in different ways. So in some cases it may be not a case of 'evil partner, hiding your banner', but a 'stupid browser which does not support feature "X" or functionality "Y" e t.c.'. May be it could be also treated as a problem on your partner's side, but to make that clear - you should tell him, which browsers must display the banner correctly.

So, what to do?

Impossibility of full automatic check does not means that you should not do anything. You can perform some sorts of checking, like in suggestions above - and, I think. that will divide your partners into 2 parts: those, who passed your check and those, who failed. So, at least you'll not have to check first part manually - thus, it's a way to save your time. Second part could be checked only manually to be 100% sure - and each specific case should be handled separately so you'll be sure that it's 100% fault of your partner.

Upvotes: 1

Related Questions