Forum Moderators: open

Message Too Old, No Replies

ASP Script How To Question

Managed To Find a Script To Extract Keywords From URL...But Need Help!

         

sinclasc

10:10 pm on Nov 19, 2005 (gmt 0)

10+ Year Member



Hi guys,
I managed to find a script to isolate and display keywords from a URL. It works great, but it doesn't know where to cut off (i.e. it displays the keywords from the string, and anything after the keywords).
Any help appreciated! The ASP Code is below:

<%
On Error Resume Next

Dim strReferer
strReferer = LCase(Request.ServerVariables("HTTP_REFERER"))
strURL = LCase(Request.ServerVariables("QUERY_STRING"))
blnSearchReferral = False
blnInsiteReferral = False
strError = "404"
strSite = ""

Function Custom()
If Len(strReferer)<>0 Then
'We have been referred to this page some another web page ...
If (InStr(1,strReferer,".looksmart.co") > 0) OR (InStr(1,strReferer,".ifind.freeserve") > 0) OR (InStr(1,strReferer,".ask.co") > 0) OR (InStr(1,strReferer,"google.co") > 0) OR (InStr(1,strReferer,"altavista.co") > 0) OR (InStr(1,strReferer,"msn.co") > 0) OR (InStr(1,strReferer,"hotbot.co") > 0) OR (InStr(1,strReferer,"yahoo.co") > 0) Then
'we have been referred to from a known search engine
blnSearchReferral = True
arrSite = Split(strReferer,"/")
arrParams = Split(strReferer,"?")
strSearchTerms = arrParams(1)
arrParams = Split(strSearchTerms,"&")
strSite = arrSite(2)
sQryStr = ""

' Define what search terms are in use
' Be sure to Dim the array length appropriately
Dim arrQueryStrings(4)
arrQueryStrings(0) = "q="//google, altavista, msn
arrQueryStrings(1) = "p="//yahoo
arrQueryStrings(2) = "ask="//ask jeeves
arrQueryStrings(3) = "qt="//looksmart
arrQueryStrings(4) = "query="//hotbot

Dim i,q
For i=0 To UBound(arrParams)
'loop through all the parameters in the referring page's URL
For q=0 To UBound(arrQueryStrings)
sQryStr = arrQueryStrings(q)
If (InStr(1,arrParams(i),sQryStr)) Then
'we've found a search term!
strSearchTerms2 = Split(strSearchTerms,sQryStr)
strSearchTerms = strSearchTerms2(1)
strSearchTerms = Replace(strSearchTerms,"+"," ")
End If
Next
Next

Response.Write "<p>Looking For " & strSearchTerms & "</strong>?. We're The Experts!.</p>"

End If

End If
End Function
%>

ItzFX

12:03 am on Nov 24, 2005 (gmt 0)

10+ Year Member



Not sure if this will completey work but here's what I think needs to be done:
For the following part of the code near the end:
Dim i,q
For i=0 To UBound(arrParams)
'loop through all the parameters in the referring page's URL
For q=0 To UBound(arrQueryStrings)
sQryStr = arrQueryStrings(q)
If (InStr(1,arrParams(i),sQryStr)) Then
'we've found a search term!
strSearchTerms2 = Split(strSearchTerms,sQryStr)
strSearchTerms = strSearchTerms2(1)
strSearchTerms = Replace(strSearchTerms,"+"," ")
End If

You need to add a bit to get rid of everything BUT the query. Just change that whole section to:
Dim i,q
For i=0 To UBound(arrParams)
'loop through all the parameters in the referring page's URL
For q=0 To UBound(arrQueryStrings)
sQryStr = arrQueryStrings(q)
If (InStr(1,arrParams(i),sQryStr)) Then
'we've found a search term!
strSearchTerms2 = Split(strSearchTerms,sQryStr)
strSearchTerms = strSearchTerms2(1)
strSearchTerms = Replace(strSearchTerms,"+"," ")
If (InStr(1,strSearchTerms,"&")) Then
strSearchTerms_temp = split(strSearchTerms,"&")
strSearchTerms = strSearchTerms_temp(0)
End If
End If

Hope that helps