View Single Post
Old 11-06-2011, 04:40 PM  
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,174
Here is a different way to do it. Not saying it's better, just different ;p

Code:
<?php
// Housekeeping

// Initialize stuff
$domain=array();
$ads=array();

// define the ad that will be shown if the domain is not in your list 
$ad2use="defaultad";

// define the various ads you will use for domains in your list
$ad1="ad 1 code goes here";
$ad2="ad 2 code goes here";
$ad3="ad 3 code goes here";

// for each domain that you want an ad for define the domain in $domain[] and the ad in $ad[]
// I store everything like this lower case 

// site group 1
$domain[1]="domain1";
$ads[1]=$ad1;
$domain[2]="domain2";
$ads[2]=$ad1;

//site group 2
$domain[3]="domain3";
$ads[3]=$ad2;
$domain[4]="domain4";
$ads[4]=$ad2;

// site group 3
$domain[5]="domain5";
$ads[5]=$ad3;

// etc etc for as many site-ad groups as you want

// End of Housekeeping

// Mainline

// check to see if there is anything in referer
if(isset($_SERVER['HTTP_REFERER']))
{
  // loop through the domain list
  for($domcnt=1;$domcnt<=count($domain);$domcnt++)
  {
    // is the domain name in the referer string?  Checking lowercase because I have the domain list lowercased  
    if(substr_count(strtolower($_SERVER['HTTP_REFERER']),$domain[$domcnt])>0)
    {
      // if the domain was in the referer string then grab the associated ad
      $ad2use=$ads[$domcnt];
      // break out of the for... loop
      $break;
    }
  }
}

// put the selected ad up there
echo $ad2use;

// end of Mainline

?>
__________________
All cookies cleared!
sarettah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote