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