PDA

View Full Version : Visitor Count and Browser Detection



Fighterfox
11-27-2010, 11:28 PM
Two separate questions here, actually.
First, I was wondering what code is best to use for printing the number of users that have visited your a certain page since a predefined date.
Then, I was wondering if I could get a count going of how many of those users have used what browser. I'm only concerned with FF, IE, Chrome, Safari, and Opera. As to the browser detection, I thought about using this code:


function whichBrs() {
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("opera") != -1) return 'Opera';
if (agt.indexOf("staroffice") != -1) return 'Star Office';
if (agt.indexOf("webtv") != -1) return 'WebTV';
if (agt.indexOf("beonex") != -1) return 'Beonex';
if (agt.indexOf("chimera") != -1) return 'Chimera';
if (agt.indexOf("netpositive") != -1) return 'NetPositive';
if (agt.indexOf("phoenix") != -1) return 'Phoenix';
if (agt.indexOf("firefox") != -1) return 'Firefox';
if (agt.indexOf("safari") != -1) return 'Safari';
if (agt.indexOf("skipstone") != -1) return 'SkipStone';
if (agt.indexOf("msie") != -1) return 'Internet Explorer';
if (agt.indexOf("netscape") != -1) return 'Netscape';
if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
if (agt.indexOf('\/') != -1) {
if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
return navigator.userAgent.substr(0,agt.indexOf('\/'));}
else return 'Netscape';} else if (agt.indexOf(' ') != -1)
return navigator.userAgent.substr(0,agt.indexOf(' '));
else return navigator.userAgent;
}

I would like to output these values directly to the page of interest. I appreciate any help very much!

Fighterfox
11-30-2010, 01:15 AM
Well, suppose I was considering using this browser detection code:


function whichBrs() {
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("opera") != -1) return 'Opera';
if (agt.indexOf("staroffice") != -1) return 'Star Office';
if (agt.indexOf("webtv") != -1) return 'WebTV';
if (agt.indexOf("beonex") != -1) return 'Beonex';
if (agt.indexOf("chimera") != -1) return 'Chimera';
if (agt.indexOf("netpositive") != -1) return 'NetPositive';
if (agt.indexOf("phoenix") != -1) return 'Phoenix';
if (agt.indexOf("firefox") != -1) return 'Firefox';
if (agt.indexOf("safari") != -1) return 'Safari';
if (agt.indexOf("skipstone") != -1) return 'SkipStone';
if (agt.indexOf("msie") != -1) return 'Internet Explorer';
if (agt.indexOf("netscape") != -1) return 'Netscape';
if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
if (agt.indexOf('\/') != -1) {
if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
return navigator.userAgent.substr(0,agt.indexOf('\/'));}
else return 'Netscape';} else if (agt.indexOf(' ') != -1)
return navigator.userAgent.substr(0,agt.indexOf(' '));
else return navigator.userAgent;
}

How could I use this code to print the user's browser to the screen? Also, is it JavaScript or PHP that I need to use for this stuff (like browser visitor count from a particular date)?

jscheuer1
11-30-2010, 04:02 AM
If you use javascript and only javascript, only users with javascript enabled will see the version. Also - javascript alone has no way of keeping track from user to user how many of which browser have visited.

A program like:

Google Analytics (http://www.google.com/analytics/)

or another third party site statistics program might be right for you.

Your host may even provide something that could be used in whole or in part for this.

For a pure PHP solution, start here:

http://php.net/manual/en/function.get-browser.php

You will also need to use PHP's file reading and writing capabilities or a database to store and to retrieve the information for display to the user.

Or find a ready made PHP script for the purpose(s) you intend.