Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

how to use classes correct

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

how to use classes correct

Postby maxmin » Mon Nov 04, 2002 5:59 pm

hi ,

i am new to PHP and want to use a class i found on the net (client_info, to detect browser and platform). this class contains a function that returns the browser of the user.

ok, so i made i made a new instance of the class:
$info = new client_info;

then i tried to echo:
echo $info->get_client_browser();

but i did't work.
could someone give me a hint how to use a class in the right way?
thanks:max.
maxmin
New php-forum User
New php-forum User
 
Posts: 3
Joined: Mon Nov 04, 2002 5:52 pm

Postby 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
Dmitrit Plakhotnik
New php-forum User
New php-forum User
 
Posts: 13
Joined: Fri Nov 01, 2002 6:56 am

Postby maxmin » Tue Nov 05, 2002 1:33 pm

thanks for answering, but it seems that this script is not working either...
i get no output, just a blank page.

but thanks anyway!
maxmin
New php-forum User
New php-forum User
 
Posts: 3
Joined: Mon Nov 04, 2002 5:52 pm

Postby maxmin » Tue Nov 05, 2002 2:10 pm

i changed the variable that should be analyzed to $HTTP_USER_AGENT. now it works. strange, but i am happy!
maxmin
New php-forum User
New php-forum User
 
Posts: 3
Joined: Mon Nov 04, 2002 5:52 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot] and 5 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.