1

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?

1 Answer 1

2

I've worked with an affiliate site on CodeIgniter, and the easiest thing was to simply:

http://mywebsite.com/ref/ref_id?url=whateverorthesame.com/aboutus

Then in the controllers/ref.php save a cookie based on ref_id (might want to use routing for this), and simply redirect them to $this->input->get('url'). Now you can magically redirect them to others sites aswell! :)

Have them simply input the url in a text field, and through ajax:

<script type="text/javascript">
    // jQuery dependent
    $('input#url').bind('change', function() {
        $('div#copy_box').text('<?=base_url()?>ref/<?=$user->id?>?url='+encodeURIComponent($(this).val()));
    });
</script>

Simply have a text that encourages them to copy generated string.

No need to make it complicated.

4
  • Thanks, Robin. But I wanted to make it easier for the affiliates to create their links. For non technical people, it would be easier to say: add ref/ref_id to any link you want, and that's all.
    – einav
    Apr 26, 2013 at 8:46
  • 1
    For non technical people, they only have to add the url value, and you can remake it to given example if I'm not mistaken. Apr 26, 2013 at 8:54
  • OK then (-: I was hoping there was a magic solution, but apparently there isn't. Thanks for your answer. BTW, if you're familiar with affiliate systems - what type of redirect would you recommend?
    – einav
    Apr 26, 2013 at 19:14
  • Haven't thought so much about it. Not sure if 301 redirect would be good or not. Would probably make google seo better, but may cause lack of cookie savings instead. Apr 27, 2013 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.