<% Dim AffiliateID, PROMO 'Const for affiliate cookie name Const AFFILIATE_COOKIE = "AffilID" Const PROMO_COOKIE = "PROMO" 'See if the request is for host domain.com. If not, we need to 'redirect to host www.domain.com to avoid having double cookies If Left(Request.ServerVariables("HTTP_HOST"),3) <> "www" Then 'Request is for host domain.com 'Remove the affiliate cookie for this host Response.Cookies(AFFILIATE_COOKIE) = "" Response.Cookies(AFFILIATE_COOKIE).Expires = DateAdd("yyyy", -1, Date) Response.Cookies(PROMO_COOKIE) = "" Response.Cookies(PROMO_COOKIE).Expires = DateAdd("yyyy", -1, Date) 'Redirect to the same page on the www.domain.com host Dim sRedir sRedir = "http://www."& Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("URL") If Request.ServerVariables("QUERY_STRING") <> "" Then sRedir = sRedir & "?" & Request.ServerVariables("QUERY_STRING") End If Response.Redirect sRedir End If 'Request is for host www.domain.com, the proper host 'Try and get the AffiliateID from the querystring If Trim(Request.QueryString("a")) <> "" Then AffiliateID = CheckNumber(Trim(Request.QueryString("a")), "") End If 'If we found an AffiliateID from the querystring, set the cookie, 'otherwise try and get it from the cookie If AffiliateID = "" Then 'Try and get from the cookie If Request.Cookies(AFFILIATE_COOKIE) <> "" Then AffiliateID = CheckNumber(Request.Cookies(AFFILIATE_COOKIE), "") End If Else 'Set the cookie Response.Cookies(AFFILIATE_COOKIE).Expires = Date + 365 Response.Cookies(AFFILIATE_COOKIE) = AffiliateID End If 'Try to find PROMO from querystring If Trim(Request.QueryString("PROMO")) <> "" Then PROMO = Trim(Request.QueryString("PROMO")) End If 'If we found an PROMO from the querystring, set the cookie, 'otherwise try and get it from the cookie If PROMO = "" Then 'Try and get from the cookie If Request.Cookies(PROMO_COOKIE) <> "" Then PROMO = Request.Cookies(PROMO_COOKIE) End If Else 'Set the cookie Response.Cookies(PROMO_COOKIE).Expires = Date + 365 Response.Cookies(PROMO_COOKIE) = PROMO End If 'Checks a number, returning 0 if null or blank, 'or the number if valid Function CheckNumber(s, endchar) Dim x, e On Error Resume Next x = CDbl(s) e = Err.Number On Error Goto 0 If Trim(s) = "" Or IsNull(s) Or e > 0 Then CheckNumber="0" & endchar Else ' Make sure it looks valid CheckNumber=x & endchar End If End Function Function WrapLink(sLink) If PROMO <> "" Then If InStr(1, sLink, "?") > 0 Then sLink = sLink & "&PROMO=" Else sLink = sLink & "?PROMO=" End If sLink = sLink & Server.URLEncode(PROMO) End If If AffiliateID <> "" Then If InStr(1, sLink, "?") > 0 Then sLink = sLink & "&d=" Else sLink = sLink & "?d=" End If sLink = sLink & AffiliateID End If WrapLink = sLink End Function %>