CodeIgniter Forums
Create custom link url for users - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Create custom link url for users (/showthread.php?tid=67916)



Create custom link url for users - valkaycelestino - 04-24-2017

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.


RE: Create custom link url for users - InsiteFX - 04-24-2017

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.


RE: Create custom link url for users - JayAdra - 04-24-2017

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.


RE: Create custom link url for users - valkaycelestino - 04-24-2017

(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


RE: Create custom link url for users - valkaycelestino - 04-24-2017

@jay, could you please explain a little more. How do i generate the unique code?


RE: Create custom link url for users - keithmclaughlin - 04-25-2017

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.