My Page Statistic [Browser & OS]

This is a discussion on "My Page Statistic [Browser & OS]" within the Classic ASP section. This forum, and the thread "My Page Statistic [Browser & OS] are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Oct 27th, 2007, 02:38
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,612
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
My Page Statistic [Browser & OS]

Hello, since this asp thread is not much thing going on lately, let me make you guys busy for quiet some time!

I have a question. I have notice that there is some discussion in this forum regarding page statistic (their page statistic) and I am really interested to learn how to do that.
Ok, I know that I should have a code for checking the user browser and OS:
  • <%=Request.ServerVariables("HTTP_USER_AGENT")%> = OS and browser
  • <% =Request.ServerVariables("REMOTE_ADDR")%> = IP address
That would display: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.8) Gecko/20071008 Firefox/2.0.0.8

That would be a long list.
Basically, what I am trying to say here is I wanted to create a page in my site that will display all this page statistic info. Something like:

My Page Statistic
  • Browser: ??
  • Operating System: ??
  • IP Address: ??
Each time a unique user visited my site/page, I want to keep the this info in my database.

Thanks..
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Oct 27th, 2007, 23:16
Junior Member
Join Date: Oct 2007
Location: Israel
Age: 21
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Re: My Page Statistic [Browser & OS]

what kind on an info do you want to keep?

Basically, the Ip address can be the identifier column for your table and you can keep any user that his IP does not exists on the database.

to that very basic 1 column table you will add to each row any other information on the user that you want (you can look for the info on the serverVaraibles list).

more advanced, to each row you can add the current date and time and get more specific on your statics (e.g. alltime, last year, last month, last week, today, 5 minutes ago - online).

i mean to something like this: http://extremetracking.com/open;unique?login=alexucho

if you get troubles i can help.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Oct 29th, 2007, 02:58
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,612
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: My Page Statistic [Browser & OS]

Quote:
Originally Posted by Eran View Post
what kind on an info do you want to keep?

Basically, the Ip address can be the identifier column for your table and you can keep any user that his IP does not exists on the database.
Info like their Operating system (windows or mac...), their browser, and their IP address.

Ok, I must have a field (to store the IP address of the visitor) in my table...

Once they hit my site address, the main page will perform a checking of their IP address, If it exist in the database, continue to surf my site. If it does not exist, save their browser, IP address as well as their OS into my database.

Ok, I get it now..
Thanks.
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)

Last edited by Monie; Oct 29th, 2007 at 03:00.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Oct 30th, 2007, 05:14
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,612
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: My Page Statistic [Browser & OS]

Hai everyone,

I've come up with this simple code (but I ended up doing it for the whole day tho..)

It basically capture the user info like the type of browser they are using, their server software and the most important thing is their IP address, and store them in the database.

HTML: Select all
<%
Dim ipadd, browser, serversw
ipadd = Request.ServerVariables("remote_addr")
browser = Request.ServerVariables("http_user_agent")
serversw = Request.ServerVariables("server_software")
%>
HTML: Select all
<%    
    Do while not pg.EOF
        If pg("ipaddress") = ipadd Then 'If the user IP address appear to be exist in the database already, just redirect them to the main page!
            pg.Close
            pgConn.Close
            set pg=nothing
            set pgConn=nothing
            Response.Redirect("default.asp")
        End If  
    pg.MoveNext
    Loop

    'If the user IP address don't exist in the database, save them to the database..!
    Set pg = pgConn.Execute("INSERT INTO pagerank (ipaddress, browser, serversoftware) VALUES ('" & ipadd & "', '" & browser & "', '" & serversw & "')")
    Response.Redirect("default.asp")
%>
Now I can do my page rank statistic...
If there is any better way, please share, Thanks..
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)

Last edited by Monie; Nov 1st, 2007 at 07:19.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Nov 1st, 2007, 14:01
Junior Member
Join Date: Oct 2007
Location: Israel
Age: 21
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Re: My Page Statistic [Browser & OS]

amm, yes you can.

instead of looping all your database you can do it with a simpler query.
something like this:


HTML: Select all
sql = "SELECT * FROM pagerank WHERE ipaddress='" & ipadd & "'"

...

if not pg.EOF
    Set pg = pgConn.Execute("INSERT INTO pagerank (ipaddress, browser, serversoftware) VALUES ('" & ipadd & "', '" & browser & "', '" & serversw & "')")
I'm just not sure if my is statement is correct


secondly, why are need the redirection for?
you can make this code rows as a new page and add it to each page (you can add to the static the current page...).
that way, if a user will surf directly to "default.asp" the static will "know" him.

and to loss some extra load on your database you will create a cookie (with chocolate's chips), after you adding a new user (by unique IP) or verifying that this user is already in exists in your database, that says 'hi! did i surfed here before?'.
and finally you will add the damn question if the cookie exist than do the ip check.

good luck m8 :P
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Nov 2nd, 2007, 03:51
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,612
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: My Page Statistic [Browser & OS]

Wow.. Thanks again Eran!

I'll have a look at your way and try them in my page ASAP.
I'll let you know if I manage to do it
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Nov 2nd, 2007, 04:46
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,612
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: My Page Statistic [Browser & OS]

Hai Eran, I have come up with this! Looks more effective tho..
I never tought of that before.. Thanks to you

About the cookie things.. I might learn that bit. I am using session variable in my login page tho..
Code: Select all
    Set pg = pgConn.Execute("SELECT * FROM mypagerank WHERE ipaddress = '" & ipadd & "' ")

    If not pg.EOF Then
        'If the user IP address exist in the database, do nothing and close connection!
        pg.Close
        pgConn.Close
        set pg=nothing
        set pgConn=nothing
    Else
        'If it don't exist, Saved them!
        Set pg = pgConn.Execute("INSERT INTO mypagerank (ipaddress, browser, serversoftware, year, month) VALUES ('" & ipadd & "', '" & browser & "', '" & serversw & "', '" & visitYear & "', '" & visitMonth & "')")
    End If
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Nov 2nd, 2007, 08:07
Junior Member
Join Date: Oct 2007
Location: Israel
Age: 21
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Re: My Page Statistic [Browser & OS]

any time


cookies is a very like the same as sessions except that the cookie is saved only on the user pc and session cost you on the server as well.
cookies - unsecured. any website or man or hacker can see it (you can see it on the cookies folder).
session - secured. saved on the server. :secret:
the thing is that we don't want unnecessary data on the server. it will slow your website down. therefor try to use as slightly as you can with sessions.

first, I saw you use redirection and by that users can bypass your static page directly to your main page so i suggest you to put the static code on any page that you want without the redirection thing.

second, the cookie thing is to loose stress on the database that when i reload the page it won't connect to the db again for nothing.

3rd, you got this terrific site that can be very useful for ya
http://www.w3schools.com/asp/asp_cookies.asp

eace:
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Nov 2nd, 2007, 08:18
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,612
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: My Page Statistic [Browser & OS]

you seems good in asp Eran nice to have you here..

As you notice, I have throw away the redirect thing and seems that I coded them in a very effective way.

About the cookies thing, that I will keep that in mind.
Now, everytime the user visit my main page, the page will "rerun" the If Then Else statement.
That I have to look into now....
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Nov 5th, 2007, 05:54
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,612
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: My Page Statistic [Browser & OS]

Solved it!
Just add some session checking and the code will no longer be run everytime the page load/refreshed!

Code: Select all
    If Session("saved") <> "saved" Then 'If session value is not equal the value "saved", this code will not be executed!
       open the database connection, saved the user IP address and
       set session("saved") = "saved"
    End If
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Nov 5th, 2007, 13:28
Junior Member
Join Date: Oct 2007
Location: Israel
Age: 21
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Re: My Page Statistic [Browser & OS]

i meant u do that on cookies to easier the server.

nice work :P
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Nov 6th, 2007, 00:27
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,612
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: My Page Statistic [Browser & OS]

yeah, I am learning that now, I mean how to use cookies instead of session object
Thanks for the advice.
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old Nov 12th, 2007, 01:50
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,612
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: My Page Statistic [Browser & OS]

and... my final question...!

I am using this code to get the browser type: <%=Request.ServerVariables("HTTP_USER_AGENT")%> = "a long list of browser type here"

and in my sql database I will write like this:
SELECT * FROM mydatabase WHERE browser =
"a long list of browser type here"

Is there a way for me to get the result like this:
browser = Firefox or EI7 or Safari or IE6.. instead of the long list I get from the code above?
Thanks..
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #14  
Old Nov 15th, 2007, 16:18
Junior Member
Join Date: Oct 2007
Location: Israel
Age: 21
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Re: My Page Statistic [Browser & OS]

nop

Once I copied i file from "webwiz" forum that can do what you want - if you want you can search it on their website...

the main idea is to check if IE6 is in the text and to determine the browser type.
they got a long list of browser type and versions there. very useful. i suggest you go search or ask for it on there website. gL!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #15  
Old Nov 17th, 2007, 07:11
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,612
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: My Page Statistic [Browser & OS]

I would be thankful if you could send me the file that you are talking about
I don't know what to search for Eran..
Thanks.
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #16  
Old Nov 17th, 2007, 17:38
Junior Member
Join Date: Oct 2007
Location: Israel
Age: 21
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Re: My Page Statistic [Browser & OS]

browser.txt
web_wiz_forums_lite_v7[1].9

i didn't found this on their latest versions so maybe they upgraded this old function :] try to ask them on their community...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #17  
Old Nov 21st, 2007, 06:07
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,612
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: My Page Statistic [Browser & OS]

Wow Eran, that code is good!
Brilliant you!
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #18  
Old Nov 23rd, 2007, 12:03
Junior Member