How can I log visitor details like IP address and visited paths?
The type of data that you're asking about is usually not stored by this type of script.
If you take a look at the way the database for this sample is configured, you'll see that
we simply count requests for each unique page and that we don't actually store any
individual user data.
While it is certainly possible to log details such as the client computer's IP address
and the paths that a user visits to a database, you'll find that your database will get
quite large very quickly. Unless you have a very good reason to implement this
level of detail in your logging, it's almost always overkill.
Think for a few minutes why you're trying to capture this data. If you don't need to
have real-time access to the data, the easiest alternative is to utilize your Web-server's
log files. Things like IP address and requested URLs are already logged there by default.
You'll need to check the documentaion for your server or with your hosting facility, but
almost all of them provide some level of access to your Web site's log files.
If you find that you really do require access to this data from your application, try to
keep the amount of data that you actually log to a minimum. For example, a visitor's IP address
and user agent (aka. browser software and version) is usually static for the life of their session.
Data of that sort can simply be captured once per session (via something like Session_OnStart)
instead of once per page request. If you need help figuring out what client data to store,
you may find our Server Variables sample useful.
Remember that data is only as good as the conclusions you can draw from it and the
actions you take based on those conclusions. Storing mountains and mountains of
information just to say that you have it doesn't do anyone any good.
There's a reference to adovbs.inc in the code. What is it, why doesn't it work without it, and where can I get it?
When writing database related code in ASP, you're really using
ADO (ActiveX Data Objects) which is Microsoft's set of components
which provide programmatic database access. ADO defines a lot of
different constants which you can use to make code more readable
and easier to follow and debug. In order to use these constants
in VBScript you need to define them. This is where adovbs.inc
comes in.
The adovbs.inc file contains a list of the ADO constants and
their numerical equivilents and when included in your ASP code,
it defines them as constants so you have access to them in your
code. There are a lot of these constants and most of our code
is relatively simple database code so it only uses a few of
them, but some you might recognize are adOpenStatic,
adLockReadOnly, adCmdText, etc...
The reason the code doesn't work when you forget to include
the file is that the constants the code uses aren't defined.
The result is that incorrect values get passed to ADO and it
doesn't know what to do with them.
In terms of getting a copy, you probably already have one!
Do a search on your system for adovbs.inc and you'll almost
certainly find the copy that was installed with ADO. If you
can't find one you can get a copy of the one I'm currently using
for the samples from here.
Please note: This form is only for submitting questions about the sample for us to consider including in the FAQ. If we feel the question merits inclusion, we will include it along with a reply. We will not respond to your email individually.