Get this Code: Click to download the ASP file.
Do not copy and paste the displayed code. The display function adds line breaks so what you see is definitely not what you would get.
Code for this Example. (Keyword Capture)
<%
' function library include for search word extraction
function CaptureKeywords(strIn,strMarker)
dim startPoint
dim endPoint
dim temp
strMarker = strMarker & "="
startPoint = instr(strIn,strMarker)
if startPoint > 0 then
endPoint = instr(startPoint,strIn,"&") ' _
instr(strIn,"&") 'instr(strIn,"&")
temp = mid(strIn,startPoint + len(strMarker),len(strin) - _
instr(startPoint,strIn,"&"))
if endpoint <> 0 then temp = _
left(temp,instr(temp,"&") - 1)
else
temp = ""
end if
CaptureKeywords = temp
end function
function URLDecode(strIn)
dim i
dim strRet
dim temp
if len(strIn) > 0 then
for i = 1 to len(strIn)
temp = mid(strIn, i, 1)
temp = replace(temp, "+", " _
")
If temp = "%" and len(strIn) > _
i + 2 then
temp = mid(strIn, i + 1, 2)
temp = chr(cint("&H" & temp))
i = i + 2
end if
strRet = strRet & temp
next
URLDecode = strRet
end if
end function
function ExtractSearch()
dim hostname
dim refer
dim search
dim strMarker
hostname = _
lcase(request.servervariables("HOSTNAME"))
refer = _
lcase(request.servervariables("HTTP_REFERER"))
if refer <> "" or instr(refer,hostname) > _
0 then
if instr(refer,"google") > 0 or _
instr(refer,"msn") > 0 then
strMarker = "q"
end if
if instr(refer,"yahoo") > 0 then
strMarker = "p"
end if
end if
ExtractSearch = URLDecode(CaptureKeywords(refer,strMarker))
end function
function ExtractSearchEngine()
dim hostname
dim refer
dim search
dim strMarker
hostname = _
lcase(request.servervariables("HOSTNAME"))
refer = _
lcase(request.servervariables("HTTP_REFERER"))
if refer <> "" or instr(refer,hostname) > _
0 then
if instr(refer,"google") > 0 then
ExtractSearchEngine = "Google"
end if
if instr(refer,"msn") > 0 then
ExtractSearchEngine = "MSN"
end if
if instr(refer,"yahoo") > 0 then
ExtractSearchEngine = "Yahoo"
end if
else
ExtractSearchEngine = ""
end if
end function
' drex function
function RE_URLDecode(str)
dim re
set re = new RegExp
str = Replace(str, "+", " ")
re.Pattern = "%([0-9a-fA-F]{2})"
re.Global = True
URLDecode = re.Replace(str, _
GetRef("URLDecodeHex"))
end function
' Replacement function for the above
function URLDecodeHex(match, hex_digits, pos, source)
URLDecodeHex = chr("&H" & hex_digits)
end function
%>

