Thread: OS Stats
View Single Post
  #3   Spotlight this post!  
Unread 15-11-2002, 15:09
Brandon Martus's Avatar Unsung FIRST Hero
Brandon Martus Brandon Martus is offline
busy.
AKA: B. Slash Kamen
no team
 
Join Date: May 2001
Rookie Year: 1998
Location: Nevada, TX USA
Posts: 5,271
Brandon Martus has a reputation beyond reputeBrandon Martus has a reputation beyond reputeBrandon Martus has a reputation beyond reputeBrandon Martus has a reputation beyond reputeBrandon Martus has a reputation beyond reputeBrandon Martus has a reputation beyond reputeBrandon Martus has a reputation beyond reputeBrandon Martus has a reputation beyond reputeBrandon Martus has a reputation beyond reputeBrandon Martus has a reputation beyond reputeBrandon Martus has a reputation beyond repute
Send a message via ICQ to Brandon Martus Send a message via AIM to Brandon Martus Send a message via Yahoo to Brandon Martus
You can do it with javascript, yes.

If you want to record/handle it on server-side, however, you can use a few things in PHP.

To get the OS in our 'stats' section on chiefdelphi.com ... we use a vBulletin hack. Here is the code (yes, its ugly.. i didnt write it ):

Code:
if(ereg("Win", getenv("HTTP_USER_AGENT"))) $c_os = "Windows";
elseif((ereg("Mac", getenv("HTTP_USER_AGENT"))) || (ereg("PPC", getenv("HTTP_USER_AGENT")))) $c_os = "Mac";
elseif(ereg("Linux", getenv("HTTP_USER_AGENT"))) $c_os = "Linux";
elseif(ereg("FreeBSD", getenv("HTTP_USER_AGENT"))) $c_os = "FreeBSD";
elseif(ereg("SunOS", getenv("HTTP_USER_AGENT"))) $c_os = "SunOS";
elseif(ereg("IRIX", getenv("HTTP_USER_AGENT"))) $c_os = "IRIX";
elseif(ereg("BeOS", getenv("HTTP_USER_AGENT"))) $c_os = "BeOS";
elseif(ereg("OS/2", getenv("HTTP_USER_AGENT"))) $c_os = "OS/2";
elseif(ereg("AIX", getenv("HTTP_USER_AGENT"))) $c_os = "AIX";
else $c_os = "Other";
Then, $c_os will have the user's operating system.

And, ugly-coded browser detection:
Code:
if((ereg("Nav", getenv("HTTP_USER_AGENT"))) || (ereg("Gold", getenv("HTTP_USER_AGENT"))) || (ereg("X11", getenv("HTTP_USER_AGENT"))) || (ereg("Mozilla", getenv(
"HTTP_USER_AGENT"))) || (ereg("Netscape", getenv("HTTP_USER_AGENT"))) AND (!ereg("MSIE", getenv("HTTP_USER_AGENT")))) $c_browser = "Netscape";
elseif(ereg("MSIE", getenv("HTTP_USER_AGENT"))) $c_browser = "MSIE";
elseif(ereg("Lynx", getenv("HTTP_USER_AGENT"))) $c_browser = "Lynx";
elseif(ereg("Opera", getenv("HTTP_USER_AGENT"))) $c_browser = "Opera";
elseif(ereg("WebTV", getenv("HTTP_USER_AGENT"))) $c_browser = "WebTV";
elseif(ereg("Konqueror", getenv("HTTP_USER_AGENT"))) $c_browser = "Konqueror";
elseif((eregi("bot", getenv("HTTP_USER_AGENT"))) || (ereg("Google", getenv("HTTP_USER_AGENT"))) || (ereg("Slurp", getenv("HTTP_USER_AGENT"))) || (ereg("Scooter", getenv("HTTP_USER_AGENT"))) || (eregi("Spider", getenv("HTTP_USER_AGENT"))) || (eregi("Infoseek", getenv("HTTP_USER_AGENT")))) $c_browser = "Bot";
else $c_browser = "Other";
$c_browser has the browser in it.


And, another way .. you would make this script, load it in a browser, and see what happens:



The following example shows how one might list all available information retrieved about the user's browser.

Example 1. get_browser() example

Code:
<?php
function list_array ($array) {
    while (list ($key, $value) = each ($array)) {
    $str .= "<b>$key:</b> $value<br />\n";
    }
    return $str;
}
echo "$HTTP_USER_AGENT<hr />\n";
$browser = get_browser();
echo list_array ((array) $browser);
?>
The output of the above script would look something like this:

Code:
Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586)<hr />
<b>browser_name_pattern:</b> Mozilla/4\.5.*<br />
<b>parent:</b> Netscape 4.0<br />
<b>platform:</b> Unknown<br />
<b>majorver:</b> 4<br />
<b>minorver:</b> 5<br />
<b>browser:</b> Netscape<br />
<b>version:</b> 4<br />
<b>frames:</b> 1<br />
<b>tables:</b> 1<br />
<b>cookies:</b> 1<br />
<b>backgroundsounds:</b> <br />
<b>vbscript:</b> <br />
<b>javascript:</b> 1<br />
<b>javaapplets:</b> 1<br />
<b>activexcontrols:</b> <br />
<b>beta:</b> <br />
<b>crawler:</b> <br />
<b>authenticodeupdate:</b> <br />
<b>msn:</b> <br />
This, and discussion, can be found on the PHP manual: http://www.php.net/manual/en/function.get-browser.php
__________________
Brandon Martus
e-mail

Last edited by Brandon Martus : 15-11-2002 at 15:20.