First let me ask you a question, does the site your putting this on give you access to mysql?
If user2 comes into your site with address that ends in ?refid=123 or some other number this code checks it and sets a cookie OR it see if as cookie exists and if yes reads it and puts into a session variable.
$_SESSION["rewards"] = '';
setcookie("njfailREWARDsystem", $_GET['refid'], time()+604800);
$value = $_COOKIE["njfailREWARDsystem"];
$_SESSION["rewards"] = $value;
echo $_SESSION["rewards"]; // ONLY here for show
You should be having trouble with the code you published
, are you?