1,105,546 Community Members

User Referral System PHP, MySQL ?

Member Avatar
phplover
Junior Poster in Training
97 posts since Jul 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-1
 

Hi,

I have a fully pledged membership system and want to integrate my own user referral system but want some tips, advice really on the logic of it. Basically already registered users on my site will have the option to refer people, only registered users. I will try to explain my logic and what i have done so far.

My current registered users table is something like

users (table)
- id (user id)
- email (user email)
- password (hash of users password)
- reg_date (date user registered)

I have some other fields but not relevant to what I want to do and to keep things as simple as possible I left them out.

I am thinking of creating a new table called referrals and for example when a registered user on my site from the users table goes to a member only page called referral.php it will display a form so they can enter an email address of someone they want to refer and it also displays the people they referred.

My referral table is like this so far and not sure if it's best way to go about the database logics and php logic.

my table so far looks like this:

referrals (table)
- id (auto incremented every time a new referral (row) is added to referrals table)
- referrer_uid (id of referrer, this would be the unique id of a registered user from the users table)
- referred_email (email address of person who has been referred)
- status (when someone is first referred default will be `referred`, if they signup to site via referral link this will update to `completed`)
- created_on (date the referral was made, unix timestamp)
- updated_on (date the referred person actually clicks the referral link and completes signup)

Currently i added the database table above to my site on local. added some sample data for testing and created a referral.php page where there's a form so a registered member can enter a persons email and refer them to my site to signup. On referral.php there is also the total people they referred and a table showing all the people they referred as follows:

Referred Email | Referred Date | Status | Completed On

Now so far everything is seems fine. I have my sample (pretend referrals i made) data showing in my test account. The part i am now not sure about is this:

Obviously to stop abuse i do my usual validation checks like: check to ensure the email being entered on referrals page does not exist in users table (registered member), check to ensure the email has not already been referred previously (for spam reasons) only allowed to refer an email address once and not allowed to refer someone who has previously been referred by someone else to (again for spam reasons)

Now onto the tracking the referral and link building.

I was first thinking this:

on sign up form have a hidden field. The sign up form would do a simple check to see if isset $_GET like signup.php?ref=something_here

if it is prefill the hidden field, when user then signs up if the ref=something_here matches what's in the database then update referral to complete so the referrer knows that their friend for example signed up via their referral, unix timestamp of when referred person completed signup.

Now i was going to use the email address of referred person or username of person who made the referral signup.php?ref=username or signup.php?ref=referred_email . Now what i am thinking is what would be better and i guess stop random abuse is create another column and call it referred_id; this would be a random md5 hash that is unique to that referral and it will be appended to the url like signup.php?ref=md5_hash_here.

So my questions are:

1) Is there anything you think i should change, improve on, alter etc ?

2) Do you think i am going about it the rite way or making a mess of it ?

3) Have i left anything out that i may have not thought of that could cause the system to be abused ?

Any suggestions, feedback, help on the whole logic would be great.

I coded allot of it last night and won't take me long to do the rest but need some help in terms of ensuring i am doing it the best way possible etc, the logic behind it all.

Thanks for any suggestions, help, advice, tips!

PHPLOVER

Member Avatar
jkon
Posting Pro in Training
444 posts since Jan 2009
Reputation Points: 110 [?]
Q&As Helped to Solve: 74 [?]
Skill Endorsements: 6 [?]
 
0
 

Keep your question clear and as short as possible, nobody will even read those…. If there is a question behind it rephrase it.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: