|
|
|
php วิธีตรวจสอบค่า browser ว่าเป็นของ ค่ายไหน ตัวอะไร version เท่าไร ทำไงเหรอ |
|
|
|
|
|
|
|
Code (PHP)
<?PHP
class Browser
{
private $props = array("Version" => "0.0.0",
"Name" => "unknown",
"Agent" => "unknown") ;
public function __Construct()
{
$browsers = array("firefox", "msie", "opera", "chrome", "safari",
"mozilla", "seamonkey", "konqueror", "netscape",
"gecko", "navigator", "mosaic", "lynx", "amaya",
"omniweb", "avant", "camino", "flock", "aol");
$this->Agent = strtolower($_SERVER['HTTP_USER_AGENT']);
foreach($browsers as $browser)
{
if (preg_match("#($browser)[/ ]?([0-9.]*)#", $this->Agent, $match))
{
$this->Name = $match[1] ;
$this->Version = $match[2] ;
break ;
}
}
}
public function __Get($name)
{
if (!array_key_exists($name, $this->props))
{
die "No such property or function $name)" ;
}
return $this->props[$name] ;
}
public function __Set($name, $val)
{
if (!array_key_exists($name, $this->props))
{
SimpleError("No such property or function.", "Failed to set $name", $this->props) ;
die ;
}
$this->props[$name] = $val ;
}
}
?>
Code (PHP)
<?PHP
$browser = new Browser ;
echo "$Browser->Name $Browser->Version" ;
?>
|
|
|
|
|
Date :
2015-05-20 14:59:35 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
error นะ บรรทัดที่ 31 ลองเช็คสคริปดู
|
|
|
|
|
Date :
2015-05-21 12:57:42 |
By :
paravatee |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ใส่วงเล็บครอบ message
die( "No such property or function $name" );
|
|
|
|
|
Date :
2015-05-21 15:30:29 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|