title: Replace an img src value based on a referring URL's query string
body: <p>I have a Magento store and I would like to replace the <code>src</code> value of an img based on whether the referring URL contains a specific querystring or querystring value (adnetwork=as) and if not simply leave the image as it is.</p>
  
  <p>Is this simple enough to do, I've searched everywhere for the answer, and even asked on various forums to no avail.</p>
  
  <p>Here's what I have so far, seems like the correct syntax, just Firebug reports that it is unable to load the image URL, and it simply shows "". The paths are correct and have been tested.</p>
  
  <pre><code>&lt;?php
  
  // Path for default image source
  $logo = $this-&gt;getSkinUrl('images/logo.gif');
  
  // Get the referrer url from the $_SERVER array, or false if it's empty
  $referrer = empty($_SERVER['HTTP_REFERER']) ? false : $_SERVER['HTTP_REFERER'];
  
  // If the referrer exists
  if($referrer) {
  
      // parse the url for the query
      $query_str = parse_url($referrer, PHP_URL_QUERY);
  
      // If there's a query string
      if(!empty($query_str)) {
          // Parse it and put the array into $components
          parse_str($query_str, $components);
  
          // If the "adnetwork" component is set
          if(!empty($components['adnetwork'])) {
              // Set the $logo var to the adnetwork image source
              $logo = $this-&gt;getSkinUrl('images/logo-no-number.gif');
          }
      }
  }
  
  ?&gt;
  
  &lt;div class="header"&gt;
  
      &lt;img class="shop24" src="&lt;?php echo $this-&gt;getSkinUrl('images/shop-24.gif') ?&gt;" alt="Shop Online 24 Hours a Day"/&gt;
  
      &lt;div class="shopping-bag"&gt;&lt;?php echo $this-&gt;getChildHtml('topcart')?&gt;&lt;/div&gt;
  
      &lt;div id="fplogo"&gt;&lt;a href="&lt;?php echo $this-&gt;getUrl('') ?&gt;" title="Sale Basins - Clickbasin.co.uk"&gt;&lt;img src="&lt;?php echo $logo; ?&gt;" alt="Sale Basins - Clickbasin.co.uk" /&gt;&lt;/a&gt;&lt;/div&gt;
  
      &lt;img src="&lt;?php echo $this-&gt;getSkinUrl('images/side_logo_promo.gif') ?&gt;" alt="Promotion" class="side-logo-promo"/&gt;
  
      &lt;?php echo $this-&gt;getChildHtml('topMenu') ?&gt;
  
      &lt;?php //&lt;?php echo $this-&gt;getLogoSrc() ?&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>I hope you can help guys. Thanks.</p>