Where'd They Come From?: Recording Referrals in ASP - How Do The URLs Get In The Table? (Page 3 of 4 )
This is the final step to creating our project; we must create a page that contains the code that will record where the user came from, i.e. the site that had the link that they clicked on. First we will find where the user came from using the request method, pretty simple really:
RefURL = Request.ServerVariables("HTTP_REFERER")
We connect to the database using the DSNless connection like in the last file:
If the InsertIntoID was not 0, then we must update the existing URL by adding 1 to the count:
SQL_query = "UPDATE RefTable SET Counter = Counter + 1 WHERE Ref_ID =" & InsertIntoID MyConn.Execute(SQL_query) END IF
MyConn.Close Set MyConn = nothing %>
How Do I Use It?
To put this to use, all you have to do is call the file ref.asp in your default page, or whatever other page you want to record referrals. This is done by using Server Side Includes:
This simply gets all the code from the file Ref.asp and places it in the file that you include it in, very handy for the head tag, or the top of your page, this way you only change one file and every file that calls upon the changed file will be altered.
To view the results of your referral counter, simply go to the file referrals.asp page, and it will be displayed for you.