Display a page on your website for known referrers Print

Version française disponible ici

You are a very good webdesigner and you have lots of clients. That’s fine. Now imagine that lots of these websites have a commun theme about the same kind of business activity.

For marketing reason, you want to display on your own site a specific page when visitors click on your web address shown on the footer of these client sites.

So, how to accomplish this redirection, depending of your referrers in a minimum of work without the need to change all inbound Urls?

Statistic sofwares can be a good inspiration: a PHP global variable retrives the inbound link referrers.

Based on this fact, these lines of code can be added in a form named “referrers”:

  1. <txp:php>
  2. /**
  3. ** @script: grab referrer domains from a list and redirect to a specific page
  4. **
  5. ** @author: Patrick LEFEVRE <patrick[dot]lefevre[at]gmail[dot]com>
  6. ** @date: 12/09/2010
  7. ** @revision: 04/02/2012
  8. ** @version 2
  9. **/
  10. // grab referrers
  11. $ref = @$_SERVER['HTTP_REFERER'];
  12. // sanitize Urls
  13. if(!empty($ref))
  14. {
  15. $ref = str_replace('www.', '', parse_url($ref));
  16. // List of external Urls
  17. $s[0] = 'pixar.com';
  18. $s[1] = 'disney.fr';
  19. $s[2] = 'dreamworks.com';
  20. $s[3] = 'macguff.com';
  21. // if an Url is listed, serve a specific page, otherwise display the main one
  22. if (in_array($ref['host'], $s)) {
  23. header('Location: '.hu.'we-create-websites-for-animation-studios-industry');
  24. }
  25. else
  26. {
  27. header('Location: '.hu.'en');
  28. }
  29. }
  30. </txp:php>

Comments: $_SERVER['HTTP_REFERER'] grab the inbound link.
Then, this Url is sanitized in order to remove “www” characters to keep the domain even in complex schemes (see parse_url).
Your client domain names are stored into $s[] (an array).
We compare inbound link with the client domain list, then we redirect to the page or another one.

You need to change your website structure, remove all the “default” template content and add in it only this:

<txp:output_form form="referrers" />

Now put all your nain content page into a new template associated to a section (i.e “en”).

Note. This article’s subject had been adapted into a plugin available here: pat_referrers.

Published on | Updated on by Patrick LEFÈVRE.

Related Articles

Pat_tile, a plugin for your articles title - Publié le 2013.04.26 By Patrick LEFÈVRE.
Hide your sections for non admin users - Publié le 2011.09.28 By Patrick LEFÈVRE.
Split your links list into columns - Publié le 2011.12.14 By Patrick LEFÈVRE.
Compress your CSS & javascript files - Publié le 2012.01.09 By Patrick LEFÈVRE.
Your comment forms in French or any other languages - Publié le 2011.12.24 By Patrick LEFÈVRE.
Access to all article archives

» Previous Article» Next Article
txp:fr supports Textpattern ;·) Textpattern CMS

Need Help? Post your question on Entr'Aide txp:fr website