Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@wmandai
Created January 4, 2014 12:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save wmandai/8254829 to your computer and use it in GitHub Desktop.
Save wmandai/8254829 to your computer and use it in GitHub Desktop.
<?php
//check for referal links
function referal()
{
$CI =& get_instance();
$cookie_value_set = $CI->input->cookie('_tm_ref', TRUE) ? $CI->input->cookie('_tm_ref', TRUE) : '';
if ($CI->input->get('ref', TRUE) AND $cookie_value_set == '') {
// referred user so set cookie to ref=username
$cookie = array(
'name' => 'ref',
'value' => $CI->input->get('ref', TRUE),
'expire' => '7776000',
);
$CI->input->set_cookie($cookie);
return TRUE;
}elseif ($cookie_value_set == '') {
$cookie = array(
'name' => 'ref',
'value' => 'sso',
'expire' => '15552000',
);
$CI->input->set_cookie($cookie);
return TRUE;
}elseif ($cookie_value_set != '') {
//already referred so ignore
return TRUE;
}else{
return TRUE;
}
}
//end of hooks file
@wmandai
Copy link
Author

wmandai commented Jan 4, 2014

Place this code in your hooks folder and name it referral.php .

@RobbiNespu
Copy link

@wmandai, why use webhook? and for referral system.. which one between using cookies or session are better option?
I assume ref link as website.com/r/uid, how to accomplish this? Any guide for me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment