Cleanse the variable, make sure it's a number.
if (isset($_GET['_repid']) and ($_GET['_repid'] > 0)) {
$myvar = $_GET['_repid'];
}
To put it in a form, you can use single quotes and concatenate,
$frm = '
<form method="post" action="somescript.php">
<input type="text" value="' . $myvar . '">
</form>
';
echo $frm;
Or double quotes and escape,
$frm = "
<form method=\"post\" action=\"somescript.php\">
<input type=\"text\" value=\"$myvar\">
</form>
";
echo $frm;
Or use double quotes but use single quotes on the form attributes, which I won't show you. There are various reasons not to use single quotes in form attributes, but since it "looks the same" and is "easier" you'll see it everywhere.
So now you have a value var, you want to set a cookie. Choose a name for the cookie, make it something identifiable so if anyone is snooping they won't suspect you of doing something sneaky (just my preference there:)
$cookiename = 'SITENAME_AFFILIATE';
set_aff_cookie($cookiename,$myvar,1800);
//
function set_aff_cookie($cname,$cvalue,$expires_in) {
$cookietime = (isset($expires_in))?$expires_in:3600;
$cookiename = (isset($cname))?$cname:'SITENAME_DEFAULT';
setcookie ($cookiename, $cvalue, time()+$cookietime, '/');
}
Cookie expire time is in milliseconds, 3600 is one hour.
Begging the next question, you'll want to read it:
$my_cookie_val = read_cookie($cookiename);
//
function read_cookie($cname) {
$this_cookie=NULL;
$cookiename = (isset($cname))?$cname:'SITENAME_DEFAULT';
if (isset($_COOKIE[$cookiename])) { $this_cookie = $_COOKIE[$cookiename]; }
return $this_cookie;
}
You may think there's not enough being done here to move these into a function, but as your site grows you will have a need for setting and reading more and different cookies. You'd just add them as you need them, for returning values from read_cookie, you return an array.