<?php
$ref = getenv("HTTP_REFERER");
$thisurl = $_SERVER["REQUEST_URI"];

setcookie ("affiliate", "1",time()+86400);

$s = $_GET['s'];
$o = $_GET['o'];

$cj = $_GET['cj'];
$ls = $_GET['ls'];
$bf = $_GET['bf'];
$p = $_GET['p'];
$sas = $_GET['sas'];
$al = $_GET['al'];
$threadless = $_GET['streetteam'];


if (isset($cj)) {
	setcookie ("aff[cj]", "$cj",time()+86400);
}

if (isset($ls)) {
	setcookie ("aff[ls]", "$ls",time()+86400);
}

if (isset($bf)) {
	setcookie ("aff[bf]", "$bf",time()+86400);
}

if (isset($p)) {
	setcookie ("aff[p]", "$p",time()+86400);
}

if (isset($al)) {
	setcookie ("aff[al]", "$al",time()+86400);
}

if (isset($threadless)) {
	setcookie ("aff[threadless]", "$threadless",time()+86400);
}

$a = "$s - $thisurl - $ref";

setcookie ("RefererCookie", "CouponitPartner",time()+31536000);
setcookie ("edit", "0",time()+1800);

$date = date("D M j g:i:s Y T");
$mnth = $today = date("Y-m");
$ip = $REMOTE_ADDR;

$add="$a <!-- $ip - $date --><br>\n";
$fp = fopen("elog/affclicks/$mnth.html", "a");
fwrite($fp, $add);
fclose($fp);

if (isset($s)) {
header ("Location: http://www.couponit.com/stores/".$s."coupons.html");
} elseif (isset($o)) {
header ("Location: http://www.couponit.com/go.couponit?o=".$o."&afsrc=1");
} else {
header ("Location: http://www.couponit.com");
}
?>
