Tweet

yellowdevils

日々すごい眠い。。。

Archive for the ‘user agent’ tag

phpでUser Agentをザックリ切り分け

without comments

簡単にざっくりブラウザーの種別をザックリ切り分けます。そんだけ。

	$v = $_SERVER['HTTP_USER_AGENT'];
	$regs = array();$OS = null;$BS = null;

	if(preg_match("/(Macintosh|Mac_PowerPC)/",$v,$regs)){
		//print_r($regs);
		$OS = "Mac";
	}
	if(preg_match("/(Windows|Win)/",$v,$regs)){
		//print_r($regs);
		$OS = "Win";
	}
	if(preg_match("/(MSIE [5-9])/",$v,$regs)){
		//print_r($regs);
		$BS = $regs[0];
	}
	if(preg_match("/(Netscape\/[7-9])/",$v,$regs)){
		//print_r($regs);
		$BS = $regs[0];
	}
	if(preg_match("/(Firefox\/[1-9])/",$v,$regs)){
		//print_r($regs);
		$BS = $regs[0];
	}
	if(preg_match("/(Safari)/",$v,$regs)){
		//print_r($regs);$BS = $regs[0];
		if(preg_match("/(Safari\/4)/",$v,$regs)){
			//print_r($regs);
			$BS = "Safari 2";
		}
		if(preg_match("/(Version\/)(\d).*(Safari)/",$v,$regs)){
			//print_r($regs);
			$BS = "Safari ".$regs[2];
		}
	}
	if(preg_match("/(Opera [6-8]|Opera\/[6-8]|Opera 9|Opera\/9)/",$v,$regs)){
		//print_r($regs);
		$BS = $regs[0];
	}
	if($BS)
		$BS = str_replace("/"," ",$BS);

	if($OS && $BS){
		//echo "---".$OS." ".$BS."---";
		$browser2 = $OS." ".$BS;
	}else{
		$browser2 = "Others";
	}

ご利用は自己責任で〜〜

Written by satoumizu

9月 12th, 2008 at 2:00 pm

Posted in develop

Tagged with ,