File: fwphp/glomodul/z_examples/book_video/03steinmetz_2008/ch08_User_and_Ses_Tracking/findbrowser.php

Recommend this page to a friend!
  Classes of Slavko Srakocic  >  B12 PHP FW  >  fwphp/glomodul/z_examples/book_video/03steinmetz_2008/ch08_User_and_Ses_Tracking/findbrowser.php  >  Download  
File: fwphp/glomodul/z_examples/book_video/03steinmetz_2008/ch08_User_and_Ses_Tracking/findbrowser.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: B12 PHP FW
Manage database records with a PDO CRUD interface
Author: By
Last change:
Date: 1 month ago
Size: 2,078 bytes
 

Contents

Class file image Download
<?php

function find_browser() {
   
// determine OS, version, and type of client browsers
   
$browser_info = array(
   
"name" => "Unknown",
   
"version" => "Unknown",
   
"OS" => "Unknown",
    );
   
// get the User Agent.
   
if (!empty($_SERVER["HTTP_USER_AGENT"])) {
   
$agent = $_SERVER["HTTP_USER_AGENT"];
    }
   
   
// find operating system
   
if (preg_match('/win/i', $agent)) {
   
$browser_info["OS"] = "Windows";
    } else if (
preg_match('/mac/i', $agent)) {
   
$browser_info["OS"] = "Macintosh";
    } else if (
preg_match('/linux/i', $agent)) {
   
$browser_info["OS"] = "Linux";
    }

    if (
preg_match('/opera/i', $agent)) {
   
// Must start with Opera, since it matches IE string
   
$browser_info["name"] = "Opera";
   
$agent = stristr($agent, "Opera");
    if (
strpos("/", $agent)) {
       
$agent = explode("/", $agent);
       
$browser_info["version"] = $agent[1];
    } else {
       
$agent = explode(" ", $agent);
       
$browser_info["version"] = $agent[1];
    }
    } else if (
preg_match('/msie/i', $agent)) {
   
$browser_info["name"] = "Internet Explorer";
   
$agent = stristr($agent,"msie");
   
$agent = explode(" ", $agent);
   
$browser_info["version"] = str_replace(";", "", $agent[1]);
    } else if (
preg_match('/firefox/i', $agent)) {
   
$browser_info["name"] = "Firefox";
   
$agent = stristr($agent, "Firefox");
   
$agent = explode("/", $agent);
   
$browser_info["version"] = $agent[1];
    } else if (
preg_match('/safari/i', $agent)) {
   
$browser_info["name"] = "Safari";
   
$agent = stristr($agent, "Safari");
   
$agent = explode("/", $agent);
   
$browser_info["version"] = $agent[1];
    } else if (
preg_match('/netscape/i', $agent)) {
   
$browser_info["name"] = "Netscape Navigator";
   
$agent = stristr($agent, "Netscape");
   
$agent = explode("/", $agent);
   
$browser_info["version"] = $agent[1];
    } else if (
preg_match('/Gecko/i', $agent)){
   
$browser_info["name"]= 'Mozilla';
   
$agent = stristr($agent, "rv");
   
$agent = explode(":", $agent);
   
$agent = explode(")", $agent[1]);
   
$browser_info["version"] = $agent[1];
    }
    return
$browser_info;
}

print_r(find_browser());

?>

For more information send a message to info at phpclasses dot org.