in a referral system, the visitor is landing on a page, like: ref.php, where you need to pass the 'parent' ID...
index.php?r=X
in index.php, you can wait this $GET["r"] variable.
if(isset($_GET["r"]))
{
// check here if there is a user with $_GET["r"] id...
//save the $_GET["r"] if it is available user into session or cookie ( session would be better!)
$_SESSION["ref"]=intval($_GET["r"]);
// here you can redirect the user to a registration page
// header("Location: registration.php"); die();
}
Now you can modify your registration script to be able to handle referrals..
$username= mysql_real_escape_string( $_POST["username"] );
$pass= mysql_real_escape_string( $_POST["password"]);
...
...
$ref=isset($_SESSION["ref"]) ? $_SESSION["ref"] : NULL;
and then save this $ref into your users table, in a referral field.