corsasport.co.uk
 

Corsa Sport » Message Board » General Chat » Little help needed with ASP script...


New Topic

New Poll
  Subscribe | Add to Favourites

You are not logged in and may not post or reply to messages. Please log in or create a new account or mail us about fixing an existing one - register@corsasport.co.uk

There are also many more features available when you are logged in such as private messages, buddy list, location services, post search and more.


Author Little help needed with ASP script...
PaulW
Member

Registered: 26th Jan 03
Location: Atherton, Greater Manchester
User status: Offline
30th Apr 04 at 18:00   View User's Profile U2U Member Reply With Quote

I'm trying to log reffering urls to a site I have to look out for, but it only seems to catch them if the referer is from the same window (ie like if you click a link from google), but if its a site which opens links in a new window (like when you click a link on a post here, it opens a new window) it won't catch the referer.

I'm guessing its because its a new window, it doesnt tag it maybe...

I'm using this method to get the referer...

Request.ServerVariables("HTTP_REFERER")

Any other ideas?
PaulW
Member

Registered: 26th Jan 03
Location: Atherton, Greater Manchester
User status: Offline
30th Apr 04 at 18:02   View User's Profile U2U Member Reply With Quote

Thought I best include the whole code...

code:
<%
Dim blnValidEntry

blnValidEntry = True

If not IsEmpty(Session("LogIn")) then blnValidEntry = False

If Left(Request.ServerVariables("HTTP_REFERER"), 31)="http://stnicholas-school.org.uk" Then
blnValidEntry = False
End If

If Left(Request.ServerVariables("HTTP_REFERER"), 35)="http://www.stnicholas-school.org.uk" Then
blnValidEntry = False
End If

If Request.ServerVariables("HTTP_REFERER") = "" Then
blnValidEntry = False
End If

If blnValidEntry Then
Const ForAppending = 8
Const Create = True
Dim FSO
Dim TS
Dim LogFileName
Dim strLog

LogFileName = Server.MapPath("logs\referers.htm")

Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Set TS = FSO.OpenTextFile(LogFileName, ForAppending, Create)
strlog = "<table width=""100%"" border=""1"" cellspacing=""0"">"
strlog = strlog & "<tr>"
strlog = strlog & "<td width=""20%"" class=""style5"">" & NOW() & "</td>"
strlog = strlog & "<td width=""20%"" class=""style5"">" & Request.ServerVariables("URL") & "?" & Request.ServerVariables("QUERY_STRING") & "</td>"
strlog = strlog & "<td width=""20%"" class=""style5""><a href=""" & Request.ServerVariables("HTTP_REFERER") & """ target=""_blank"">" & Request.ServerVariables("HTTP_REFERER") & "</a></td>"
strlog = strlog & "<td width=""40%"" class=""style1 style4"">" & Request.ServerVariables("HTTP_USER_AGENT") & "</td>"
strlog = strlog & "</tr></table>"

TS.write strlog
TS.Writeline ""

Session("LogIn") = "yes"
Set TS = Nothing
Set FSO = Nothing

End If
%>

Dom
Member

Registered: 13th Sep 03
User status: Offline
30th Apr 04 at 19:13   View User's Profile U2U Member Reply With Quote

no, when a new window is opened, there isnt a referer heading Only way to do it mate, if you want to log where there from is by IP address, then do a DNS on them and do it that way Atleast you will know what ISP there using, but thats about it mate
PaulW
Member

Registered: 26th Jan 03
Location: Atherton, Greater Manchester
User status: Offline
30th Apr 04 at 19:16   View User's Profile U2U Member Reply With Quote

aye I'm already getting that via the normal web-logs, its I was just asked to get this info by the head as he wants to know who is linking to us...

bugger
Ian
Site Administrator

Avatar

Registered: 28th Aug 99
Location: Liverpool
User status: Offline
30th Apr 04 at 19:37   View Garage View User's Profile U2U Member Reply With Quote

Impossible - if the browser isn't providing this variable then you've no way of forcing it to be there. I'm sure some of the more obscure browsers can be configurered to turn it off as well - you'd never see it from these.
Ian
Site Administrator

Avatar

Registered: 28th Aug 99
Location: Liverpool
User status: Offline
30th Apr 04 at 19:39   View Garage View User's Profile U2U Member Reply With Quote

Also, why are you logging HTML tags!?

Either write them to a db or csv or something, then write a script to traverse the data and make you a page. Anything else gives you huge web pages very quickly.
Dom
Member

Registered: 13th Sep 03
User status: Offline
30th Apr 04 at 19:51   View User's Profile U2U Member Reply With Quote

put it in anyways mate and tell the head that its impossible etc

Also, btw mate, that code can be written alot simpler, by doing:

code:

<%
Dim strReferer
strReferer = Request.ServerVariables("HTTP_REFERER")

If strReferer <> "http://stnicholas-school.org.uk" or strReferer <> "http://www.stnicholas-school.org.uk" or strReferer <> "" or not IsEmpty(Session("LogIn")) then
Const ForAppending = 8
Const Create = True
Dim FSO
Dim TS
Dim strLog

Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Set TS = FSO.OpenTextFile(Server.MapPath("logs\referers.htm"), ForAppending, Create)
strlog = "<table width=""100%"" border=""1"" cellspacing=""0"">"
strlog = strlog & "<tr>"
strlog = strlog & "<td width=""20%"" class=""style5"">" & NOW() & "</td>"
strlog = strlog & "<td width=""20%"" class=""style5"">" & Request.ServerVariables("URL") & "?" & Request.ServerVariables("QUERY_STRING") & "</td>"
strlog = strlog & "<td width=""20%"" class=""style5""><a href=""" & Request.ServerVariables("HTTP_REFERER") & """ target=""_blank"">" & Request.ServerVariables("HTTP_REFERER") & "</a></td>"
strlog = strlog & "<td width=""40%"" class=""style1 style4"">" & Request.ServerVariables("HTTP_USER_AGENT") & "</td>"
strlog = strlog & "</tr></table>"

TS.write strlog
TS.Writeline ""

Session("LogIn") = "yes"
Set TS = Nothing
Set FSO = Nothing

End If
%>



although im not sure how many "or" statments you can use so it might not work, but im 90% sure that the way i just chopped it, it will
Dom
Member

Registered: 13th Sep 03
User status: Offline
30th Apr 04 at 19:54   View User's Profile U2U Member Reply With Quote

quote:
Originally posted by Ian
Also, why are you logging HTML tags!?

Either write them to a db or csv or something, then write a script to traverse the data and make you a page. Anything else gives you huge web pages very quickly.


its probably because it nice and easy mate Although yea, i agree, loading a 10+mb html page isnt the nicest thing in the world
TBH, there are loads of ways to do it, like dumping the data into a db etc But then you could add a part where it will compare the sent HTTP_REFERER head to whats in the database (storage solution) then if it isnt in the db then it will add it, otherwise it will increase a value next to the already existing HTTP_REFERER website string. But then you start to write a full blown website logger and if thats the case you might as well just download a freebie logger...plenty of them and will offer loads more info
Ian
Site Administrator

Avatar

Registered: 28th Aug 99
Location: Liverpool
User status: Offline
1st May 04 at 10:37   View Garage View User's Profile U2U Member Reply With Quote

I wouldn't check what's already in there on the write.

Just log the line, the use a grouping query to do the counting. That's how the post distribution thing in your profile works, group by forum and order by the count, descending. There's also a bit of maths in there to divide the count figure by post total and give percentage but the SQL is identical.

But yeah, if you're going to go those lenths....

 
New Topic

New Poll

Corsa Sport » Message Board » General Chat » Little help needed with ASP script... 23 database queries in 0.0107601 seconds