1 reply [Last post]
hazman
Offline
newbie
Last seen: 18 years 15 weeks ago
Timezone: GMT+2
Joined: 2004-12-19
Posts: 2
Points: 0

Hello all,

I was wondering where can I get the Browsers Today script?

Thank you

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 1 week 3 days ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5344
Points: 2965

Browsers Today script

Hi hazman,
I use this http://www.appcreator.com/visitorsnif.php to detect the browser then store the info in a mysql database using php.
This is the code to collect the data:

include("sniffer.php"); 
		$snif = new sniffer(); 
		$thedate= date('Ymd'); 
 /*You need to Connect to the DB here */ 
 
		$query= "select $snif->browser from browserstats where startdate = '$thedate'"; 
		$res=mysql_query($query); 
		if($res){ 
			$row = mysql_fetch_array($res); 
			$con= $row[$snif->browser]; 
			$con++; 
			if(mysql_num_rows($res) < 1){ 
				$query= "insert into browserstats values('$thedate', '0', '0', '0', '0', '0', '0', '0', '0' )"; 
				$res=mysql_query($query); 
			}					 
			$query= "update browserstats set $snif->browser = '$con' where startdate = '$thedate'"; 
			[email protected]_query($query); 
		}

Here's the structure of the table I call browserstats:
Field Name	Type	 
startdate 	varchar(50) 		PRI 		 
IE 	     int(5) 	 
Firefox 	int(5)  
Safari 	    int(5) 	 	 
Opera 	   int(5) 	 
Konqueror 	int(5) 	 
Netscape 	int(5) 		 
Mozilla 	int(5) 	 
Other 	int(5) 	

Here's the functions to display it
function browserstatspanel(){ 
 echo"<div class='rgh'>\n"; 
        echo"<div class='mhead' style='text-align:center' title='Browser % for visitors to this page today' >\n"; 
            echo"Browsers Today"; 
                  
        echo"</div>\n"; 
        echo"<div class='spad'>\n"; 
		$thedate=date('Ymd'); 
        /*You need to Connect to the DB here */ 
	   $query="select * from browserstats where startdate = '$thedate' "; 
	   [email protected]_query($query); 
	   [email protected]_fetch_object($res); 
	   if($row){ 
		   $sum = $row->IE + $row->Firefox + $row->Opera + $row->Netscape + $row->Mozilla + $row->Safari + $row->Konqueror; 
		   echo"<ul style='list-style:none; margin:0; padding:0;' >"; 
		  
			echo statrow($sum, $row->IE, 'Internet Explorer', 'explorer.gif', '16px', '16px'  ); 
			echo statrow($sum, $row->Firefox, 'Mozilla Firefox', 'firefox.gif' , '16px', '16px'); 
			echo statrow($sum, $row->Mozilla, 'Mozilla', 'mozilla.gif' , '16px', '20px'); 
			echo statrow($sum, $row->Netscape, 'Netscape', 'netscape.gif' , '16px', '16px'); 
			echo statrow($sum, $row->Opera, 'Opera', 'opera.gif' , '18px', '16px'); 
			echo statrow($sum, $row->Safari, 'Safari', 'safari.gif' , '16px', '16px'); 
			echo statrow($sum, $row->Konqueror, 'Konqueror', 'konqueror.gif' , '17px', '16px'); 
		   
			echo"</ul>"; 
		} 
      echo"</div>\n"; 
    echo"</div>\n"; 
 
} 
function statrow($total, $b, $alt, $img, $w, $h  ){ 
	 $per=round($b/$total *100, 0); 
	if($per > 0){ 
	   return"<li> <div class='bstat' title='$alt $per% ' style='width:$per%;'>$per % </div> 
	   <img alt='$alt' src='./attributes/images/$img' width='$w' height='$h' title='$alt' /></li>\n"; 
	}else{ 
	   return"<li><img alt='$alt' title='$alt' src='./attributes/images/$img' width='$w' height='$h' /></li>\n"; 
	} 
}

If you do a search on the web you may be able to find other simpler scripts to use.

Hope that helps