Hey Tim,
Try this (attached as well):
<?php // referrerCapture.php
$referrer = getsetReferrer();
// call this at the top of your script before you send any output, like this:
// $referrerCode = getsetReferrer();
function getsetReferrer() {
$fieldname = 'referrer';
// get referer code
if (isset($_REQUEST[$fieldname])) { $referrerCode = $_REQUEST[$fieldname]; }
elseif (isset($_COOKIE[$fieldname])) { $referrerCode = $_COOKIE[$fieldname]; }
else { $referrerCode = ''; }
// save it to a cookie (if value changed)
if ($referrerCode && $referrerCode != @$_COOKIE[$fieldname]) {
$cookieExpires = strtotime("+10 years");
$cookiePath = '/';
setcookie($fieldname, $referrerCode, $cookieExpires, $cookiePath);
}
//
return $referrerCode;
}
?>
<form method="get" action="?">
Referer: <input type="text" name="referrer" value="<?php echo htmlspecialchars($referrer); ?>" disabled="disabled" /> (you could make this a hidden field)<br/>
<input type="submit" name="submitForm" value=" Submit Form " />
</form>
Examples: <br/>
<a href="?referrer=<?php echo urlencode('ABC Corp'); ?>">Pass in a referrer</a><br/>
<a href="?">Load page without any query string (loads last referrer from cookie)</a><br/>
<a href="?referrer=<?php echo urlencode('Widgets, Inc.'); ?>">Pass in a different referrer</a><br/>
Dave Edis - Senior Developer
interactivetools.com