C and S Design.
Search Friendly Programming and Design



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. (Page Tracking)

<%
' table structure;
' accessdate - date
' accesstime - time
' session_id - varchar(255)
' remoteip - varchar(15)
' refererurl - varchar(255)
' siteurl - varchar(255)
' querystr - varchar(255)
' method - varchar(6)
' useragent - varchar(255)


const Tracking_Table = "tablename"
const str_SQL_User = "username"
const str_SQL_Pass = "password"
const str_SQL_Server = "server_name"
const str_SQL_DB = "database_name"

dim track_on
dim str_SQL_ConnString

str_SQL_ConnString = "driver={MySQL ODBC 3.51 _ 
	Driver};server=" & str_SQL_Server & ";uid=" & _ 
	str_SQL_User & ";pwd=" & str_SQL_Pass & _ 
	";database=" & str_SQL_DB & _ 
	";option=16387"

track_on = true
' set true or false to turn tracking on or off

Sub Track()
if track_on = true then
dim str_REMOTE_ADDR
dim str_HTTP_REFERER
dim str_URL
dim str_REQUEST_METHOD
dim str_HTTP_USER_AGENT
dim str_QUERY_STRING
dim str_Track_SQL

with request
str_REMOTE_ADDR = .servervariables("REMOTE_ADDR")
str_HTTP_REFERER = .servervariables("HTTP_REFERER")
str_URL = .servervariables("URL")
str_REQUEST_METHOD = _ 
	.servervariables("REQUEST_METHOD")
str_HTTP_USER_AGENT = _ 
	.servervariables("HTTP_USER_AGENT")	
str_QUERY_STRING = .ServerVariables("QUERY_STRING")
end with
SessionCode = session.sessionid

Set conn=Server.CreateObject("ADODB.Connection")
Conn.Open str_SQL_ConnString
		
str_Track_SQL = "INSERT INTO " & Tracking_Table & _ 
	" (accessdate, accesstime, session_id, remoteip, _ 
	refererurl, siteurl, querystr, method, useragent) VALUES _ 
	(now(),'" & time() & "','" & SessionCode & _ 
	"','" & str_REMOTE_ADDR & "','" & _ 
	str_HTTP_REFERER & "','" & str_URL & _ 
	"','" & str_QUERY_STRING & "','" & _ 
	str_REQUEST_METHOD & "','" & str_HTTP_USER_AGENT & _ 
	"');"
	conn.execute(str_Track_SQL)		
	conn.close
	set conn = nothing
end if
end sub

%>



Valid HTML 4.01! Valid CSS! copyright © C and S Design 2004 - 2005
Website Design and SE Friendly Coding C and S Design