Visitor Stats

J

Jon

Hi,

I'm writing a VERY BASIC stats databse for the default page of my web site.
I'm detecting various stats and saving them:

<%
visitdate = date()
visittime = time()
visitbrowser = Request.ServerVariables("HTTP_USER_AGENT")
visitreferer = Request.ServerVariables("HTTP_REFERER")
' code here for screen size
' code here to save to database
%>

I wish to also get screen resolution/size. I realise this is client side so
I can use:

<script language="JavaScript" type="text/javascript">
<!--
var screenW = screen.width
var screenH = screen.height
document.write(screenW + "x" + screenH)
//-->
</script>
But I can't save that into my database!!

Has anyone solved this problem before?

Thanks

Jon
 
T

TomB

Have a form with a hidden field, use your javascript to populate the hidden
field(s) then post the form.
 
M

Martin Honnen

Jon said:
Hi,

I'm writing a VERY BASIC stats databse for the default page of my web site.
I'm detecting various stats and saving them:

<%
visitdate = date()
visittime = time()
visitbrowser = Request.ServerVariables("HTTP_USER_AGENT")
visitreferer = Request.ServerVariables("HTTP_REFERER")
' code here for screen size
' code here to save to database
%>

I wish to also get screen resolution/size. I realise this is client side so
I can use:

<script language="JavaScript" type="text/javascript">
<!--
var screenW = screen.width
var screenH = screen.height
document.write(screenW + "x" + screenH)
//-->
</script>
But I can't save that into my database!!

You can try
<script type="text/javascript">
document.write('<img alt="" src="log.asp?width='
+ screen.width
+ '&height=' + screen.height
+ '" width="0" height="0">');
</script>
then in log.asp you store those values from the query string.
 
J

Jon

Have a form with a hidden field, use your javascript to populate the
hidden
field(s) then post the form.

When I considered the form idea I figured the problem is that it needs
posting, that is it won't work as the visitor goes to the page.

I'm going to have a try with Martins idea. I considered at the 'top' of the
page write the info to a cookie using javascript, at the 'end' of the page
retrieving this information using vbscript for my database?!

Jon
 
J

Jon

Sorted, thanks Martin.

The result:

index.htm or whatever:

<script language="JavaScript" type="text/javascript">
document.write('<img alt="" src="log.asp?width=' + screen.width +
'&height=' + screen.height + '" width="0" height="0">');
</script>

log.asp:

<%
dim conn, strsql, rsuser, strMDBPath
set conn=server.createobject("ADODB.Connection")
set rsuser=server.createobject("ADODB.Recordset")
strMDBpath = Server.MapPath("stats.mdb")
conn.open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & strMDBPath

visitdate = date()
visittime = time()
visitbrowser = Request.ServerVariables("HTTP_USER_AGENT")
visitreferer = Request.ServerVariables("HTTP_REFERER")
if visitreferer = "" then
visitreferer = "None shown"
end if
visitscreenresolution = request.QueryString("width") & "x" &
request.QueryString(+"height")

sql="INSERT INTO tblVisitors (visitdate, visittime, visitbrowser,
visitreferer, visitscreenresolution) VALUES ('" & visitdate & "', '" &
visittime & "', '" & visitbrowser & "', '" & visitreferer & "', '" &
visitscreenresolution & "');"

conn.Execute sql

conn.close
set rsuser=nothing
set conn=nothing
%>

Almost worthy of an FAQ ?????

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top