Suppose there are 2 tables. One for users and other for reference. User table has a unique primary key called user_id. Now a user registers in this site and the system assigns a unique user id to that user. Suppose it is
1 and username is
demo. Now you need to create a page called referrer.php and put the id and username as encoded e.g.
U8061IU9KDLP004RS (You can use any types of encoding as you like).
$encoded_referral_ID = base64_encode($id.$username);
?>
So that the new users referrer url is:
http://www.example.com/referrer.php?ref_id=U8061IU9KDLP004RS
Now this url is being published in social media and other websites. And then a visitor clicks that link. So the next process is:
In referrer.php you need to get the id and decode it. Then check the id & username with your user table whether it is there and valid. If yes then insert a record into referral id and redirect the visitor to the register page. Make it sure to have a status field in referral table. At the time of first insert, set the status as 0. After the visitor completing the registration, set the status 1.
Hope that make you sense..
Rony