| |
Audience: Those who know VB and ASP (or ASP programmers in general) who want to get access to HTTP server variables.
Introduction: Ever wonder who's visiting your website? Many have resorted to using services such as IMCHAOS to log people's screen names who have clicked on their other's links. However, many are starting to realize that IMCHAOS is tracking people's names and therefore defeating the whole purpose.
In this tutorial I will show a simple way to get access to HTTP headers that the user will send to the server. This will include the IP address along with other information the user's browser will send to the server.
Note: when taking someone's ip through a webserver, it's always nice to notify the user that you're doing this ;) You may want to put a disclaimer that you will be doing this. Then have them enter your site and log the information at that time.
Here's some of the server variables we'll be working with. All of these variables are built in to ASP: Request.ServerVariables("REMOTE_ADDR") -- the IP address of the visitor Request.ServerVariables("HTTP_USER_AGENT") -- the browser the user uses to visit your site Request.ServerVariables("HTTP_REFERER") -- where the user was before he/she came to your site
Example: This example will show how to access these HTTP variables and then append them to a text file located on the server.
<%
dim filesys, filetxt
Const ForWriting = 2, ForAppending = 8
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.OpenTextFile(Server.MapPath("*PATH*"), ForAppending, True)
filetxt.WriteLine("<p>")
filetxt.WriteLine("IP=" & Request.ServerVariables("REMOTE_ADDR"))
filetxt.WriteLine("<br>")
filetxt.WriteLine("Date: " & Date() & " at " & Time() &".")
filetxt.WriteLine("<br>")
filetxt.WriteLine("HTTP_USER_AGENT=" & Request.ServerVariables("HTTP_USER_AGENT"))
filetxt.WriteLine("<br>")
filetxt.WriteLine("HTTP_REFERER=" & Request.ServerVariables("HTTP_REFERER"))
filetxt.WriteLine("</p>")
filetxt.Close
Set filetxt = Nothing
Set filesys = Nothing
%>
|
Constraints: *PATH* - this refers to a path where you can write to.
Explanation: Everything should be pretty self explanatory, if you know VB and ASP. The only note I have should be that you can change ForAppending to ForWriting if your rather write to the file instead of appending.
Set filesys = CreateObject("Scripting.FileSystemObject") Set filetxt = filesys.OpenTextFile(Server.MapPath("*PATH*"), ForAppending, True)
|
|