Location: PHPKode > projects > PhpWebDesk > phpWebDesk/browscap.inc.php
<?php
//
// phpWebDesk browser recognition file
//

// Does basically the same job as browscap, just using stristr() (less reliable, but probably
// faster and definately easier.

// Outputs $omode (0-HTML, 1-WML, 2-ASCII). These mode codes should match that of the [convert_m.php] file.
// Outputs $imgmode (0-PNG,1-JPEG,2-GIF,3-BMP,4-WBMP). These mode codes should match that of the [convert_img.php] file.

require_once "config.inc.php";

// Check to see if auto update is on.
if ($autoupdate) {
# Get date of current file
clearstatcache();
$bc_time = filemtime($browscappath);
# See if it's more than a week (604800 seconds) old
if ((time()-$bc_time)>604800) {
# Download and update file
$new_browscap.=file_get_contents($browscapurl);
$fn = fopen($browscappath, "w");
$new_browscap.=fputs($fn, $new_browscap);
fclose($fn);
} 
}

// Use browscap.csv (comma separated values) file to get the info.
// WARNING: can be slow. Change config.inc.php to use browscap.ini if possible.
$fn = fopen($browscappath, "r");

# Get description line & remove speech marks & square brackets
$line = str_replace(array("\"", "[", "]"), "", explode(",", fgets($fn)));

# Find # of useragent, system & wap capability parameter
foreach($line as $key=>$value) {
    if (stristr($value, "UserAgent")) {$uakey = $key;}
    if (stristr($value, "Platform")) {$pkey = $key;}
    if (stristr($value, "Win16")) {$w16key = $key;}
    if (stristr($value, "WAP")) {$wapkey = $key;}
}

# Load EVERY SINGLE BROWSER until we find one matching our useragent.
while(!feof($fn)) {
    $line = str_replace(array("\"", "[", "]"), "", explode(",", fgets($fn)));
    if(stristr($line[$uakey], $_SERVER['HTTP_USER_AGENT'])) {
        $dowap = $line[$wapkey];
        $dosys = $line[$pkey];
        if (stristr($dowap, "default")) { $mode = 0;}
        if (stristr($dowap, "false")) { $mode = 0;}
        if (stristr($dowap, "true")) { $mode = 0;}
        # And use alternative image formats if we come across win95 or a 16-bit system (quite rare)
        if (stristr($dosys, "Win95")) { $imgmode = $altimgformat;}
        if (stristr($line[$w16key], "true")) { $imgmode = $altimgformat;}
    }
}
fclose($fn);
Return current item: PhpWebDesk