content based on referrer

mediastar100

New member
Apr 26, 2008
1,443
12
0
Has anyone got a quick piece of php code i could use to customize some text based on the traffic referrer?

Im still learning my php 101.

me<-:zzwhip: <- php

thanks
 


Write it in pseudo code and I'll help you.

e.g if referer = 'google.com' tell him to fuck off
 
I'm not trying to be funny.

PHP:
$var1 = 'www.google.com';
$var2 = 'www.youtube.com';

if ($_SERVER['HTTP_REFERER'] == $var1) {
  // print content
} elseif ($_SERVER['HTTP_REFERER'] == $var2) {
  // print content
}
This is the basic approach, if I've understood what you want correctly. The best approach would be to create an array with domains and loop through those elements. PM me with specific needs and I'll help you.
 
For speed reasons I usually do the following to refrain from for foreach loops or expensive array searches.

PHP:
$sites['www.google.com'] = 'Content A';
$sites['www.yahoo.com'] = 'Content B';

$ref = ((isset($_SERVER['HTTP_REFERER']) ? strtolower($_SERVER['HTTP_REFERER']) : false);

if(!$ref || !isset($sites[$ref])) {
  echo 'normal content';
} else {
  echo $sites[$ref];
}