how to use classes correct

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Post Reply
Dmitrit Plakhotnik
New php-forum User
New php-forum User
Posts: 13
Joined: Fri Nov 01, 2002 6:56 am

Post by Dmitrit Plakhotnik » Tue Nov 05, 2002 1:02 am

This is incorrect class, if you need browser/OS info use this:

Example:

<?

$t = new client_info();
echo $t->browser;

class client_info
{
var $platform;
var $browser;

function client_info()
{
$this->platform = "Unknown";
// Determine the platform they are on
if (strstr($this->get_user_agent(),'Win'))
$this->platform='Windows';
else if (strstr($this->get_user_agent(),'Mac'))
$this->platform='Macintosh';
else if (strstr($this->get_user_agent(),'Linux'))
$this->platform='Linux';
else if (strstr($this->get_user_agent(),'Unix'))
$this->platform='Unix';
else
$this->platform='Other';


// Next, determine the browser they are using
if ( preg_match("/Opera ([0-9]\.[0-9]{0,2})/i", $this->get_user_agent(), $found) &&
strstr($this->get_user_agent(), "MSIE") )
{
// This will identify the Opera browser even when it tries to ID itself
// as MSIE 5.0
$this->browser = "Opera " . $found[1];
}
else if ( preg_match("/Opera ([0-9]\.[0-9]{0,2})/i", $this->get_user_agent(), $found) &&
strstr($this->get_user_agent(), "Mozilla") )
{
// Finds Opera if ID's itself as Mozilla based browser
$this->browser = "Opera " . $found[1];
}
else if ( preg_match("/Opera\/([0-9]\.[0-9]{0,2})/i", $this->get_user_agent(), $found) )
{
// Finds Opera when ID'ing itself as Opera
$this->browser = "Opera " . $found[1];
}
else if ( preg_match("/Netscape[0-9]\/([0-9]{1,2}\.[0-9]{1,2})/i", $this->get_user_agent(), $found) )
{
// For Netscape 6.x
$this->browser = "Netscape " . $found[1];
}
else if ( preg_match("/Mozilla\/([0-9]{1}\.[0-9]{1,2}) \[en\]/i", $this->get_user_agent(),$found) )
{
// For Netscape 4.x
$this->browser = "Netscape " . $found[1];
}
else if ( preg_match("/MSIE ([0-9]{1,2})/i", $this->get_user_agent(), $found) )
{
// For MSIE
$this->browser = $found[0];
}
else
$this->browser = $this->get_user_agent();
}

// Return the platform detected
function get_client_platform()
{
return ($this->platform);
}

// Return the browser that we detected
function get_client_browser()
{
return ($this->browser);
}

// Return the user agent string
function get_user_agent()
{
global $HTTP_ENV_VARS; // $HTTP_ENV_VARS - global array!!!
return $HTTP_ENV_VARS["HTTP_USER_AGENT"];
}

}
?>

--
Sincerely,
Dmitriy S. Plakhotnik
AlarIT programmer
http://www.AlarIT.com

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests