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?

einav
  • 553
  • 9
  • 27

1 Answers1

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.

Robin Castlin
  • 10,956
  • 1
  • 28
  • 44
  • 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 '13 at 08: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. – Robin Castlin Apr 26 '13 at 08: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 '13 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. – Robin Castlin Apr 27 '13 at 11:59