1. Add a new field to user/registered.users table via phpmyadmin control panel(mysql, "add new field after x"), example name it "ref" (example. user with id "1" refers an new user who future id(after registration) is "2" and so into field "ref" will be inserted "1" (the user 1 referred him))
2. The users "1" personal ref URL looks something like this url/-------1 (the users id).
This URL should insert a cookie to a visitor browser and sets value ref="1", expires example in 1 month. (modify your index page or if you have a header separately add cookie command to it. the command that saves the referral value to new users pc)
(search Google cookies and php)
So I suggest retrieve the ref value to registration form from a cookie, and after new user(future id "2") clicks register, the email, name etc.. now also ref fields will be inserted/saved to db(you need to add a new insert value "ref", should be inserted like other users info, just need to add a new field).
php example add new user to database:
mysql(insert int user (email, name, ref) values (dd@dd.com, Oskar, $ref));
Also add cash to the old user "1" for referring "2" example: 15+to the account balance.
php example update old user and credit him:
mysql(update user set cashbalance=cashbalance+15 where id=1);
This is to identify who referred who. and credits it directly.
So it will be done with PHP