CodeIgniter Forums

Full Version: Create custom link url for users
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a membership site where people can sign up for an account using their name, phone number and password of choice. The information entered during registration is stored in a MySQL database table called 'users'. The primary key in the users table is the phone number. During sign up, the user has the option to type the phone number of his referrer into 'referrer' field.
I have all these set up and working fine, but I want to enhance the site some more, by:
  1. Creating a unique referral link for users which will have their phone number appended to their link. I want to track which user referred others to my site so I can reward them.
  2. When they share this link, and people click on it, it will take them to the registration page (register.php). On that page he phone number of the referrer will be set (and locked) in the 'referrer' box.
I am new to php and Code Igniter. I have toured the internet looking for a solution to this but i just can't find any. Please any help will be much appreciated.
I Did this a long time ago using CodeIgniter and Xajax javascript.

It is not an easy task to do, we had to use CodeIgniter's _remap() method
to grab the url's etc;

When I have the time I plan on porting the code over to CodeIgniter and jQuery.

But I would start by reading up on the _remap() method.
I feel like this would be fairly simple to do?

You could generate a unique code to build your "referral link" for that user (e.g. http://www.mysite.com/refer/4Fg5GdXC45).

In the controller function "refer", you'd just look up which user that code belongs to, fetch their phone number, and pass that to the view. Or better yet, just send along the referrer user id and pull the phone number when processing the form submission. That way the user can't edit the locked fields using the console etc.
(04-24-2017, 04:35 AM)InsiteFX Wrote: [ -> ]I Did this a long time ago using CodeIgniter and Xajax javascript.

It is not an easy task to do, we had to use CodeIgniter's _remap() method
to grab the url's etc;

When I have the time I plan on porting the code over to CodeIgniter and jQuery.

But I would start by reading up on the _remap() method.

Will give it a try. Thanks
@Jay, could you please explain a little more. How do i generate the unique code?
I agree with JayAdra. It shouldn't be that hard to accomplish.

In your users table add 2 fields; referral_code & referral_count.

When adding users to the table create a random string using the string helper and set the referral_code to that string and set the referral_count to 0 as default.

Then when the user wants to refer someone provide them a link like Jay said: http://www.mysite.com/refer/4Fg5GdXC45 and when it gets visited update the user who has 4Fg5GdXC45 as their referral_code and +1 to the referral_count.

You can grab the last piece of the link using the URI class.