ah - so the surfer comes in with referralCode=xxxx and you want to send them out with the same?
Then, yup, store the referral code in a session cookie and collect it on the way out....
Code:
coming in:
if(!empty($_GET['referralCode'])) setcookie("referralCode", $_GET['referralCode']);
goin out:
if(isset($_COOKIE['referralCode'])) print"<a href=\"http://somedomain.com/index.php?referralCode=".$_COOKIE['referralCode']."\">Now click away</a>";
else print"<a href=\"http://somedomain.com/index.php\">Now click away</a>";