您的位置:首页 > 编程语言 > PHP开发

php判断浏览器类型

2009-03-06 20:26 295 查看
<?php
	//baseAgent类,抽象的基类
	abstract class baseAgent
	{
	    abstract function PrintPage();
	}
	//ieAgent类,用于客户端是IE时调用的类
	class ieAgent extends baseAgent
	{
	    function PrintPage()
	    {
	        return "当前浏览器是IE!";
	    }
	}
	//otherAgent类,用于客户端不是IE时调用的类
	class otherAgent extends baseAgent
	{
	    function PrintPage()
	    {
	        return "当前浏览器不是IE!";
	    }
	}
	//判断并创建不同的对象类型,对象名为$currPage
	if(strstr($_SERVER["HTTP_USER_AGENT"], "IEAGENT"))
	{
	    $currPage = new ieAgent();
	} 
	else
	{
	    $currPage = new otherAgent();
	}
	//输出
	echo $currPage->PrintPage();
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: