title: How to design an affiliate system on CodeIgniter, to use on every page on the site?
body: <p>I'm designing an affiliate system for an e-commerce site on CodeIgniter, and am wondering what is the best approach for it.</p>
  
  <p>I want the affiliates to be able to link to each and every page on the website.</p>
  
  <p>So ideally, the affiliates would copy the desired link on my website, add some identifying suffix, and use it as the referral link.</p>
  
  <p>I thought I'd instruct the affiliate to add a <code>/ref/ref_id</code> suffix to every link, and then use <code>$this-&gt;uri-&gt;uri_to_assoc(n)</code> in my header (i.e - on every page), and look for the pair <code>'ref' =&gt; 'ref_id'</code> in the resulting array.</p>
  
  <p>The problem is that some of the pages have an even number of segments in the uri, and others have an odd number of segments.</p>
  
  <p>so, <code>mywebsite.com/item/item_id/ref/ref_id</code> would yield:</p>
  
  <pre><code>array
    'item' =&gt; 'item_id' 
    'ref' =&gt; 'ref_id' 
  </code></pre>
  
  <p>Which is great. But <code>mywebsite.com/aboutus/ref/ref_id</code> would yield:</p>
  
  <pre><code>array
   'aboutus' =&gt; 'ref'
   'ref_id' =&gt; false
  </code></pre>
  
  <p>Which is not very helpful.</p>
  
  <p>Also, I cannot use this syntax on the homepage itself (<code>mywebsite.com/ref/ref_id</code>) because I get a 404 page not found, since there's no <code>ref</code> function in my home controller.</p>
  
  <p>The other option I thought was to use query string (<code>mywebsite.com/about?ref=ref_id</code>), but that doesn't seem very CodeIgniterish, doesn't it?</p>
  
  <p>So what would be the best way to implement this?</p>