⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 phpsniff.core.php

📁 一个用PHP编写的
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/*******************************************************************************	$Id: phpSniff.core.php,v 1.16 2003/07/02 23:30:29 epsilon7 Exp $        phpSniff: HTTP_USER_AGENT Client Sniffer for PHP	Copyright (C) 2001 Roger Raymond ~ epsilon7@users.sourceforge.net	This library is free software; you can redistribute it and/or    modify it under the terms of the GNU Lesser General Public    License as published by the Free Software Foundation; either    version 2.1 of the License, or (at your option) any later version.    This library is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    Lesser General Public License for more details.    You should have received a copy of the GNU Lesser General Public    License along with this library; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*******************************************************************************//** * \ingroup Net_HTTP * * The PHPSniff package provides support for detecting the browser capabilities at run-time. * */class phpSniff_core{   // initialize some vars	var $_browser_info = array(    	'ua'         => '',    	'browser'    => 'Unknown',    	'version'    => 0,    	'maj_ver'    => 0,    	'min_ver'    => 0,    	'letter_ver' => '',    	'javascript' => '0.0',    	'platform'   => 'Unknown',    	'os'         => 'Unknown',    	'ip'         => 'Unknown',        'cookies'    => 'Unknown', // remains for backwards compatability    	'ss_cookies' => 'Unknown',        'st_cookies' => 'Unknown',    	'language'   => '',		'long_name'  => '',		'gecko'      => '',        'gecko_ver'  => ''		);		var $_feature_set = array(		'html'		 =>	true,		'images'	 =>	true,		'frames' 	 =>	true,		'tables'	 =>	true,		'java'		 =>	true,		'plugins'	 => true,		'iframes'	 => false,		'css2'		 =>	false,		'css1'		 =>	false,		'xml'		 =>	false,		'dom'		 =>	false,		'wml'		 =>	false,		'hdml'		 =>	false,        'xmlhttpreq' => false 		);		var $_quirks = array(		'must_cache_forms'			=>	false,		'avoid_popup_windows'		=>	false,		'cache_ssl_downloads'		=>	false,		'break_disposition_header'	=>	false,		'empty_file_input_value'	=>	false,		'scrollbar_in_way'			=>	false		);	var $_get_languages_ran_once = false;	var $_browser_search_regex = '([a-z]+)([0-9]*)([0-9.]*)(up|dn|\+|\-)?';	var $_language_search_regex = '([a-z-]{2,})';	    /**     *  init     *  this method starts the madness     **/    function init ()    {           //  collect the ip        	$this->_get_ip();        //  run the cookie check routine first        //  [note: method only runs if allowed]        	$this->_test_cookies();		//  rip the user agent to pieces        	$this->_get_browser_info();        //	gecko build			$this->_get_gecko();		//  look for other languages        	$this->_get_languages();		//  establish the operating platform        	$this->_get_os_info();		//  determine javascript version        	$this->_get_javascript();		//	determine current feature set			$this->_get_features();		//	point out any quirks			$this->_get_quirks();	}    /**     *  property     *  @param $p property to return . optional (null returns entire array)     *  @return array/string entire array or value of property     **/    function property ($p=null)    {   if($p==null)        {   return $this->_browser_info;        }        else        {   return $this->_browser_info[strtolower($p)];        }    }		/**	 *	get_property	 *	alias for property	 **/	function get_property ($p)	{	return $this->property($p);	}    /**     *  is     *  @param $s string search phrase format = l:lang;b:browser     *  @return bool true on success     *  ex: $client->is('b:OP5Up');     **/    function is ($s)    {   // perform language search		if(preg_match('/l:'.$this->_language_search_regex.'/i',$s,$match))        {   if($match) return $this->_perform_language_search($match);        }        // perform browser search        elseif(preg_match('/b:'.$this->_browser_search_regex.'/i',$s,$match))        {   if($match) return $this->_perform_browser_search($match);        }        return false;    }		/**	 *	browser_is	 *	@param $s string search phrase for browser	 *  @return bool true on success     *  ex: $client->browser_is('OP5Up');	 **/	function browser_is ($s)	{	preg_match('/'.$this->_browser_search_regex.'/i',$s,$match);		if($match) return $this->_perform_browser_search($match);	}		/**	 *	language_is	 *	@param $s string search phrase for language	 *  @return bool true on success     *  ex: $client->language_is('en-US');	 **/	function language_is ($s)	{	preg_match('/'.$this->_language_search_regex.'/i',$s,$match);		if($match) return $this->_perform_language_search($match);	}		/**	 *	has_feature	 *	@param $s string feature we're checking on	 *  @return bool true on success     *  ex: $client->has_feature('html');	 **/	function has_feature ($s)	{	return $this->_feature_set[$s];	}		/**	 *	has_quirk	 *	@param $s string quirk we're looking for	 *  @return bool true on success     *  ex: $client->has_quirk('avoid_popup_windows');	 **/	function has_quirk ($s)	{	return $this->_quirks[$s];	}    /**     *  _perform_browser_search     *  @param $data string what we're searching for     *  @return bool true on success     *  @private     **/    function _perform_browser_search ($data)    {   $search = array();		$search['phrase'] 		= isset($data[0]) ? $data[0] : '';		$search['name']   		= isset($data[1]) ? strtolower($data[1]) : '';		$search['maj_ver']   	= isset($data[2]) ? $data[2] : '';		$search['min_ver']   	= isset($data[3]) ? $data[3] : '';		$search['direction']	= isset($data[4]) ? strtolower($data[4]) : '';		        $looking_for = $search['maj_ver'].$search['min_ver'];        if($search['name'] == 'aol' || $search['name'] == 'webtv')        {   return stristr($this->_browser_info['ua'],$search['name']);        }        elseif($this->_browser_info['browser'] == $search['name'])        {   $majv = $search['maj_ver'] ? $this->_browser_info['maj_ver'] : '';            $minv = $search['min_ver'] ? $this->_browser_info['min_ver'] : '';            $what_we_are = $majv.$minv;            if(($search['direction'] == 'up' || $search['direction'] == '+')                && ($what_we_are >= $looking_for))            {   return true;            }			elseif(($search['direction'] == 'dn' || $search['direction'] == '-')                   && ($what_we_are <= $looking_for))			{	return true;			}            elseif($what_we_are == $looking_for)            {   return true;            }        }		return false;    }    function _perform_language_search ($data)    {   // if we've not grabbed the languages, then do so.        $this->_get_languages();        return stristr($this->_browser_info['language'],$data[1]);    }    function _get_languages ()    {   // capture available languages and insert into container        if(!$this->_get_languages_ran_once)        {   if($languages = getenv('HTTP_ACCEPT_LANGUAGE'))            {   $languages = preg_replace('/(;q=[0-9]+.[0-9]+)/i','',$languages);            }            else            {   $languages = $this->_default_language;            }            $this->_set_browser('language',$languages);            $this->_get_languages_ran_once = true;        }    }    function _get_os_info ()    {   // regexes to use        $regex_windows  = '/([^dar]win[dows]*)[\s]?([0-9a-z]*)[\w\s]?([a-z0-9.]*)/i';        $regex_mac      = '/(68[k0]{1,3})|(ppc mac os x)|([p\S]{1,5}pc)|(darwin)/i';        $regex_os2      = '/os\/2|ibm-webexplorer/i';        $regex_sunos    = '/(sun|i86)[os\s]*([0-9]*)/i';        $regex_irix     = '/(irix)[\s]*([0-9]*)/i';        $regex_hpux     = '/(hp-ux)[\s]*([0-9]*)/i';        $regex_aix      = '/aix([0-9]*)/i';        $regex_dec      = '/dec|osfl|alphaserver|ultrix|alphastation/i';        $regex_vms      = '/vax|openvms/i';        $regex_sco      = '/sco|unix_sv/i';        $regex_linux    = '/x11|inux/i';        $regex_bsd      = '/(free)?(bsd)/i';        $regex_amiga    = '/amiga[os]?/i';        // look for Windows Box        if(preg_match_all($regex_windows,$this->_browser_info['ua'],$match))        {   /** Windows has some of the most ridiculous HTTP_USER_AGENT strings */			//$match[1][count($match[0])-1];            $v  = $match[2][count($match[0])-1];            $v2 = $match[3][count($match[0])-1];            // Establish NT 5.1 as Windows XP				if(stristr($v,'NT') && $v2 == 5.1) $v = 'xp';			// Establish NT 5.0 and Windows 2000 as win2k                elseif($v == '2000') $v = '2k';                elseif(stristr($v,'NT') && $v2 == 5.0) $v = '2k';			// Establish 9x 4.90 as Windows 98				elseif(stristr($v,'9x') && $v2 == 4.9) $v = '98';            // See if we're running windows 3.1                elseif($v.$v2 == '16bit') $v = '31';            // otherwise display as is (31,95,98,NT,ME,XP)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -