when you come in with an affiliate link then you need to capture the affiliate ID.
One way to do this would be to put the value of SP into a cookie that expires when the browser is closed
So
if(!empty($SP))
{
setcookie("affiliate_id",$SP,"/",0);
}
Now you have that stored away when you have your links (a href) then you simply put in the value of $SP that is in the cookie onto the end of the link.
Or the other way is to use sessions.
HTH
GM
Any questions just contact me and i'll help ya out