<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>徘徊在玻璃之城 &#187; php</title>
	<atom:link href="http://blog.znsunimage.com/tag/php/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.znsunimage.com</link>
	<description>一个身在香港的业余摄影爱好者的博客</description>
	<lastBuildDate>Fri, 23 Apr 2010 15:20:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>判断是否为手机浏览器的php程序</title>
		<link>http://blog.znsunimage.com/2009/12/950/mobile-browsers-detection</link>
		<comments>http://blog.znsunimage.com/2009/12/950/mobile-browsers-detection#comments</comments>
		<pubDate>Mon, 28 Dec 2009 07:46:04 +0000</pubDate>
		<dc:creator>SUN</dc:creator>
				<category><![CDATA[与时俱进]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.znsunimage.com/?p=950</guid>
		<description><![CDATA[当然了，这里的目的是用css来针对浏览器的不同控制排版。
&#60;?php
if(extension_loaded('zlib')){ob_start('ob_gzhandler');}
header(&#34;Content-type: text/css&#34;);
$UA=$_SERVER['HTTP_USER_AGENT'];
if (eregi(&#34;mini 9.5&#124;vx1000&#124;lge &#124;m800&#124;e860&#124;u940&#124;ux840&#124;compal&#124;wireless&#124; mobi&#124;ahong&#124;lg380&#124;lgku&#124;lgu900&#124;lg210&#124;lg47&#124;lg920&#124;lg840&#124;lg370&#124;sam-r&#124;mg50&#124;s55&#124;g83&#124;t66&#124;vx400&#124;mk99&#124;d615&#124;d763&#124;el370&#124;sl900&#124;mp500&#124;samu3&#124;samu4&#124;vx10&#124;xda_&#124;samu5&#124;samu6&#124;samu7&#124;samu9&#124;a615&#124;b832&#124;m881&#124;s920&#124;n210&#124;s700&#124;c-810&#124;_h797&#124;mob-x&#124;sk16d&#124;848b&#124;mowser&#124;s580&#124;r800&#124;471x&#124;v120&#124;rim8&#124;c500foma:&#124;160x&#124;x160&#124;480x&#124;x640&#124;t503&#124;w839&#124;i250&#124;sprint&#124;w398samr810&#124;m5252&#124;c7100&#124;mt126&#124;x225&#124;s5330&#124;s820&#124;htil-g1&#124;fly v71&#124;s302&#124;-x113&#124;novarra&#124;k610i&#124;-three&#124;8325rc&#124;8352rc&#124;sanyo&#124;vx54&#124;c888&#124;nx250&#124;n120&#124;mtk &#124;c5588&#124;s710&#124;t880&#124;c5005&#124;i;458x&#124;p404i&#124;s210&#124;c5100&#124;teleca&#124;s940&#124;c500&#124;s590&#124;foma&#124;samsu&#124;vx8&#124;vx9&#124;a1000&#124;_mms&#124;myx&#124;a700&#124;gu1100&#124;bc831&#124;e300&#124;ems100&#124;me701&#124;me702m-three&#124;sd588&#124;s800&#124;8325rc&#124;ac831&#124;mw200&#124;brew &#124;d88&#124;htc\/&#124;htc_touch&#124;355x&#124;m50&#124;km100&#124;d736&#124;p-9521&#124;telco&#124;sl74&#124;ktouch&#124;m4u\/&#124;me702&#124;8325rc&#124;kddi&#124;phone&#124;lg &#124;sonyericsson&#124;samsung&#124;240x&#124;x320vx10&#124;nokia&#124;sony cmd&#124;motorola&#124;up.browser&#124;up.link&#124;mmp&#124;symbian&#124;smartphone&#124;midp&#124;wap&#124;vodafone&#124;o2&#124;pocket&#124;kindle&#124;mobile&#124;psp&#124;treo&#124;iris&#124;3g_t&#124;windows ce&#124;opera mobi&#124;windows ce; smartphone;&#124;windows ce; iemobile&#124;ipod&#124;iphone&#124;android&#124;opera mini&#124;blackberry&#124;palm os&#124;palm&#124;hiptop&#124;avantgo&#124;fennec&#124;plucker&#124;xiino&#124;blazer&#124;elaine&#124;iris&#124;3g_t&#124;windows ce&#124;opera mobi&#124;windows ce; smartphone;&#124;windows ce; iemobile&#34;,$UA) == 1 )
{
include($_SERVER['DOCUMENT_ROOT'].&#34;/wp-content/themes/default/mobile.css&#34;);//可以替换成其他针对手机浏览器的语句
}
else
{include($_SERVER['DOCUMENT_ROOT'].&#34;/wp-content/themes/default/style.css&#34;);}

if(extension_loaded('zlib')){ob_end_flush();}
?&#62;
	
	
	&#169; SUN for 徘徊在玻璃之城, 2009. &#124;
	  Permalink &#124;
	  与时俱进 &#124; 
	  2 comments ]]></description>
			<content:encoded><![CDATA[<p>当然了，这里的目的是用css来针对浏览器的不同控制排版。</p>
<pre class="brush: php;">&lt;?php
if(extension_loaded('zlib')){ob_start('ob_gzhandler');}
header(&quot;Content-type: text/css&quot;);
$UA=$_SERVER['HTTP_USER_AGENT'];
if (eregi(&quot;mini 9.5|vx1000|lge |m800|e860|u940|ux840|compal|wireless| mobi|ahong|lg380|lgku|lgu900|lg210|lg47|lg920|lg840|lg370|sam-r|mg50|s55|g83|t66|vx400|mk99|d615|d763|el370|sl900|mp500|samu3|samu4|vx10|xda_|samu5|samu6|samu7|samu9|a615|b832|m881|s920|n210|s700|c-810|_h797|mob-x|sk16d|848b|mowser|s580|r800|471x|v120|rim8|c500foma:|160x|x160|480x|x640|t503|w839|i250|sprint|w398samr810|m5252|c7100|mt126|x225|s5330|s820|htil-g1|fly v71|s302|-x113|novarra|k610i|-three|8325rc|8352rc|sanyo|vx54|c888|nx250|n120|mtk |c5588|s710|t880|c5005|i;458x|p404i|s210|c5100|teleca|s940|c500|s590|foma|samsu|vx8|vx9|a1000|_mms|myx|a700|gu1100|bc831|e300|ems100|me701|me702m-three|sd588|s800|8325rc|ac831|mw200|brew |d88|htc\/|htc_touch|355x|m50|km100|d736|p-9521|telco|sl74|ktouch|m4u\/|me702|8325rc|kddi|phone|lg |sonyericsson|samsung|240x|x320vx10|nokia|sony cmd|motorola|up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|psp|treo|iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile|ipod|iphone|android|opera mini|blackberry|palm os|palm|hiptop|avantgo|fennec|plucker|xiino|blazer|elaine|iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile&quot;,$UA) == 1 )
{
include($_SERVER['DOCUMENT_ROOT'].&quot;/wp-content/themes/default/mobile.css&quot;);//可以替换成其他针对手机浏览器的语句
}
else
{include($_SERVER['DOCUMENT_ROOT'].&quot;/wp-content/themes/default/style.css&quot;);}

if(extension_loaded('zlib')){ob_end_flush();}
?&gt;</pre>
	<p></p>
	<hr noshade style="margin:0;height:1px" />
	<p>&copy; SUN for <a href="http://blog.znsunimage.com">徘徊在玻璃之城</a>, 2009. |
	  <a href="http://blog.znsunimage.com/2009/12/950/mobile-browsers-detection">Permalink</a> |
	  <a href="http://blog.znsunimage.com/category/tech" title="View all posts in 与时俱进" rel="category tag">与时俱进</a> | 
	  <a href="http://blog.znsunimage.com/2009/12/950/mobile-browsers-detection#comments">2 comments</a></p> ]]></content:encoded>
			<wfw:commentRss>http://blog.znsunimage.com/2009/12/950/mobile-browsers-detection/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP中远程文件的调用-关于Allow url fopen</title>
		<link>http://blog.znsunimage.com/2007/12/636/php-remote-file-in-the-call-about-allow-url-fopen</link>
		<comments>http://blog.znsunimage.com/2007/12/636/php-remote-file-in-the-call-about-allow-url-fopen#comments</comments>
		<pubDate>Mon, 17 Dec 2007 14:31:39 +0000</pubDate>
		<dc:creator>SUN</dc:creator>
				<category><![CDATA[与时俱进]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://blog.znsunimage.com/2007/12/636</guid>
		<description><![CDATA[关键词：Allow url fopen，php
最近发现blog突然出了点小问题，调试后发现是服务器提供商基于安全理由把Allow url fopen这个选项给关了，而我自己写的有一些代码中就用了相应的功能，所以导致了问题的出现，具体错误特征如下：
URL file-access is disabled in the server configuration
打开Allow url fopen的作用主要是在php程序中可以用http或者ftp方式来调用其他文件。如下面的代码：
&#60;?php include("http://example.com/includes/example_include.php"); ?&#62;
而关闭该选项后，使用上面的代码就会出错，必须换成下面的代码方可。
&#60;?php include($_SERVER['DOCUMENT_ROOT']."/includes/example_include.php"); ?&#62;
这里，系统变量 $_SERVER['DOCUMENT_ROOT']返回的是远程系统根目录。
其实现在很多服务商都把allow url fopen功能给关了，主要原因是防止黑客的注入式进攻，所以强烈建议用第二种方法来写代码。另外，如果还是想用url方式来写代码的话，可以考虑用curl。
我用这个功能主要是实现WordPress的首页静态化。我的blog首页使用了我自己hack过的af-extended-live-archive插件，这样的好处就是可以整个站用ajax方式来访问，但是加载速度就比较一般了。所以我首先生成一个静态的页面（比方说叫example.html），然后在用index.php将example.html中的内容读取出来，实现静态化。
这里大家也许会觉得奇怪，那你把首页直接重定向到example.html不就可以了……
这里我的考量主要是两点：
1. php方式可以对example.html的内容进行压缩。
2. 为了更好的SEO，我在index.php进行了判定，如果来访问的是机器人,我会把正常的页面发给它,而不是显示加载了af-extended-live-archive插件的example.html,方便机器人进行爬行抓取。
	
	
	&#169; SUN for 徘徊在玻璃之城, 2007. &#124;
	  Permalink &#124;
	  与时俱进 &#124; 
	  No comment ]]></description>
			<content:encoded><![CDATA[<p>关键词：Allow url fopen，php</p>
<p>最近发现blog突然出了点小问题，调试后发现是服务器提供商基于安全理由把Allow url fopen这个选项给关了，而我自己写的有一些代码中就用了相应的功能，所以导致了问题的出现，具体错误特征如下：</p>
<p><strong><span style="color: #ff0000;">URL file-access is disabled in the server configuration</span></strong></p>
<p>打开Allow url fopen的作用主要是在php程序中可以用http或者ftp方式来调用其他文件。如下面的代码：</p>
<p class="code" >&lt;?php include("http://example.com/includes/example_include.php"); ?&gt;</p>
<p>而关闭该选项后，使用上面的代码就会出错，必须换成下面的代码方可。</p>
<p class="code" >&lt;?php include($_SERVER['DOCUMENT_ROOT']."/includes/example_include.php"); ?&gt;</p>
<p>这里，系统变量 <code>$_SERVER['DOCUMENT_ROOT']返回的是远程系统根目录。</code></p>
<p>其实现在很多服务商都把allow url fopen功能给关了，主要原因是防止黑客的注入式进攻，所以强烈建议用第二种方法来写代码。另外，如果还是想用url方式来写代码的话，可以考虑用<a href="http://wiki.dreamhost.com/CURL_PHP_tutorial" target="_blank">curl</a>。</p>
<p>我用这个功能主要是实现WordPress的首页静态化。我的blog首页使用了我自己hack过的af-extended-live-archive插件，这样的好处就是可以整个站用ajax方式来访问，但是加载速度就比较一般了。所以我首先生成一个静态的页面（比方说叫example.html），然后在用index.php将example.html中的内容读取出来，实现静态化。</p>
<p>这里大家也许会觉得奇怪，那你把首页直接重定向到example.html不就可以了……<br />
这里我的考量主要是两点：<br />
1. php方式可以对example.html的内容进行压缩。<br />
2. 为了更好的SEO，我在index.php进行了判定，如果来访问的是机器人,我会把正常的页面发给它,而不是显示加载了af-extended-live-archive插件的example.html,方便机器人进行爬行抓取。</p>
	<p></p>
	<hr noshade style="margin:0;height:1px" />
	<p>&copy; SUN for <a href="http://blog.znsunimage.com">徘徊在玻璃之城</a>, 2007. |
	  <a href="http://blog.znsunimage.com/2007/12/636/php-remote-file-in-the-call-about-allow-url-fopen">Permalink</a> |
	  <a href="http://blog.znsunimage.com/category/tech" title="View all posts in 与时俱进" rel="category tag">与时俱进</a> | 
	  <a href="http://blog.znsunimage.com/2007/12/636/php-remote-file-in-the-call-about-allow-url-fopen#comments">No comment</a></p> ]]></content:encoded>
			<wfw:commentRss>http://blog.znsunimage.com/2007/12/636/php-remote-file-in-the-call-about-allow-url-fopen/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>搜索机器人访问控制</title>
		<link>http://blog.znsunimage.com/2007/04/562/search-access-control-robot</link>
		<comments>http://blog.znsunimage.com/2007/04/562/search-access-control-robot#comments</comments>
		<pubDate>Wed, 18 Apr 2007 04:07:11 +0000</pubDate>
		<dc:creator>SUN</dc:creator>
				<category><![CDATA[与时俱进]]></category>
		<category><![CDATA[网站更新]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[优化]]></category>

		<guid isPermaLink="false">http://blog.znsunimage.com/2007/04/562</guid>
		<description><![CDATA[关键词：搜索 机器人 Web Spider php
主页在载入速度对浏览者来说是一个比较关键的因素。一般来说，浏览者的容忍极限为5s左右，如果读取时间大于5s，浏览者往往会选择放弃。因此，我采用了现在的Live Archive方式，用 http://blog.znsunimage.com/archives.html 来代替我现在的主页，同时对该页面内的内容进行精简，将内容控制在80k以内，以提高那些新访问者的速度。
但是，相应的问题也来了。Live Archive的结构不利于搜索机器人(Web Spider)爬行，且它调用了不少的javascript内容，搜索机器人(Web Spider)无法跟踪；其次，正常主页上的诸多好友链接也被“精简”，影响了交互。虽然部分问题可以用设定robots.txt的方式来弥补，但是还是有些欠缺。
因此做了如下的处理：

让用户可以自己设定浏览方式。
用户可以通过点击左侧“我的网站”中的Live Archive/Normal Mode 来切换浏览主页的方式，同时结果保存在浏览器Cookies中，下次用同一台电脑访问时候，系统会自动根据用户喜好选择不同的浏览方式。比方说我自己就采用正常浏览方式，因为大量的内容已经被缓存在我的浏览器中，对我来说速度已经不是瓶颈问题。
将搜索机器人(Web Spider)直接引导到正常的主页，使得他们能够收集更详细全面的信息，包括我的诸多好友链接。主要参考了该网页，精简为下面的一段代码：
$UA=$_SERVER['HTTP_USER_AGENT'];
 if eregi("Googlebot&#124;Yahoo&#124;VoilaBot&#124;Ask Jeeves&#124;SpeedySpider&#124;MSNbot&#124;Yahoobot&#124;Baiduspider&#124;Sohubot&#124;Lycos&#124;Robozilla&#124;Inktomi Slurp&#124;larbin&#124;spider&#124;crawlGoogle AdSense&#124;EchO!&#124;Magpie&#124;InternetSeer&#124;Magpie&#124;Alexa&#124;The World Wide Web Worm&#124;Voyager&#124;robot&#124;Speedy Spider&#124;Motor&#124;AskJeeves&#124;GigaBot&#124;The Python Robot&#124;MSIECrawler&#124;GetBot&#124;SurveyBot&#124;Fish search&#124;Netcraft",$UA)  //大小写没有影响
{$file = "/home/znsunima/public_html/wordpress/index2.html";
ob_start('ob_gzhandler');
echo implode('', file($file));
ob_end_flush();}
 else
header("Location: http://blog.znsunimage.com/archives.html");  //见注¹


上面代码的原理是利用HTTP_USER_AGENT参数来判断是否为搜索机器人²，如果是，返回压缩过的正常主页；反之，返回Live Archive版本的主页。如果你用的是firefox，可以通过在地址栏输入“about:config”，新增general.useragent.override 字段后设定User_Agent来测试。
注¹. 其实其中的archives.html其实我也用php压缩过了，因为我的服务器不支持html格式的直接压缩
注². 网上的机器人很多，我只列了访问过我网站的和其他一些常见的Spider。
	
	
	&#169; SUN for 徘徊在玻璃之城, 2007. &#124;
	  Permalink &#124;
	  与时俱进,  网站更新 &#124; [...]]]></description>
			<content:encoded><![CDATA[<p>关键词：<em>搜索</em> <em>机器人</em> <em>Web Spider</em> <em>php</em></p>
<p><em>主页在载入速度</em>对浏览者来说是一个比较关键的因素。一般来说，浏览者的容忍极限为5s左右，如果读取时间大于5s，浏览者往往会选择放弃。因此，我采用了现在的Live Archive方式，用 <a href="http://blog.znsunimage.com/archives.html" target="_blank">http://blog.znsunimage.com/archives.html</a> 来代替我现在的主页，同时对该页面内的内容进行精简，将内容控制在80k以内，以提高那些新访问者的速度。</p>
<p>但是，相应的问题也来了。<font color="#ff99cc">Live Archive的结构不利于搜索机器人(Web Spider)爬行，且它调用了不少的javascript内容，搜索机器人(Web Spider)无法跟踪；其次，正常主页上的诸多好友链接也被“精简”，影响了交互。虽然部分问题可以用设定robots.txt的方式来弥补，但是还是有些欠缺。</font></p>
<p>因此做了如下的处理：</p>
<ol>
<li>让用户可以自己设定浏览方式。<br />
用户可以通过点击左侧“我的网站”中的<font color="#00ffff">Live Archive/Normal Mode</font> 来切换浏览主页的方式，同时结果保存在浏览器Cookies中，下次用同一台电脑访问时候，系统会自动根据用户喜好选择不同的浏览方式。比方说我自己就采用正常浏览方式，因为大量的内容已经被缓存在我的浏览器中，对我来说速度已经不是瓶颈问题。</li>
<li><font color="#ffcc99">将搜索机器人(Web Spider)直接引导到正常的主页，使得他们能够收集更详细全面的信息，包括我的诸多好友链接。</font>主要参考了该网页，精简为下面的一段代码：
<p class="code">$UA=$_SERVER['HTTP_USER_AGENT'];<br />
<font color="#00ff00"> if eregi("Googlebot|Yahoo|VoilaBot|Ask Jeeves|SpeedySpider|MSNbot|Yahoobot|Baiduspider|Sohubot|Lycos|Robozilla|Inktomi Slurp|larbin|spider|crawlGoogle AdSense|EchO!|Magpie|InternetSeer|Magpie|Alexa|The World Wide Web Worm|Voyager|robot|Speedy Spider|Motor|AskJeeves|GigaBot|The Python Robot|MSIECrawler|GetBot|SurveyBot|Fish search|Netcraft",$UA)  //大小写没有影响</font><br />
{$file = "/home/znsunima/public_html/wordpress/index2.html";<br />
ob_start('ob_gzhandler');<br />
echo implode('', file($file));<br />
ob_end_flush();}<br />
<font color="#00ff00"> else</font><br />
header("Location: <a href="http://blog.znsunimage.com/archives.html">http://blog.znsunimage.com/archives.html</a>");  //见注¹</p>
</li>
</ol>
<p>上面代码的原理是利用HTTP_USER_AGENT参数来判断是否为搜索机器人²，如果是，返回压缩过的正常主页；反之，返回Live Archive版本的主页。如果你用的是firefox，可以通过在地址栏输入“about:config”，新增general.useragent.override 字段后设定User_Agent来测试。</p>
<p>注¹. 其实其中的archives.html其实我也用php压缩过了，因为我的服务器不支持html格式的直接压缩<br />
注². 网上的机器人很多，我只列了访问过我网站的和其他一些常见的Spider。</p>
	<p></p>
	<hr noshade style="margin:0;height:1px" />
	<p>&copy; SUN for <a href="http://blog.znsunimage.com">徘徊在玻璃之城</a>, 2007. |
	  <a href="http://blog.znsunimage.com/2007/04/562/search-access-control-robot">Permalink</a> |
	  <a href="http://blog.znsunimage.com/category/tech" title="View all posts in 与时俱进" rel="category tag">与时俱进</a>,  <a href="http://blog.znsunimage.com/category/website" title="View all posts in 网站更新" rel="category tag">网站更新</a> | 
	  <a href="http://blog.znsunimage.com/2007/04/562/search-access-control-robot#comments">One comment</a></p> ]]></content:encoded>
			<wfw:commentRss>http://blog.znsunimage.com/2007/04/562/search-access-control-robot/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP判断浏览器类型和浏览器语言</title>
		<link>http://blog.znsunimage.com/2007/03/507/php-judgement-browser-type-and-language-system</link>
		<comments>http://blog.znsunimage.com/2007/03/507/php-judgement-browser-type-and-language-system#comments</comments>
		<pubDate>Tue, 13 Mar 2007 16:44:35 +0000</pubDate>
		<dc:creator>SUN</dc:creator>
				<category><![CDATA[与时俱进]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[电脑技术]]></category>

		<guid isPermaLink="false">http://blog.znsunimage.com/2007/03/14/507</guid>
		<description><![CDATA[用php语言来判断浏览器类型其实很简单。
因为浏览器在和服务器连接时候都会先发送一些包含自己信息的内容（浏览器类型、语言啦）。
这里我们主要分析的是_SERVER["HTTP_USER_AGENT"](浏览器类型)和_SERVER["HTTP_ACCEPT_LANGUAGE"](浏览器语言)。
我们所要做的就是把这些内容读出来，然后用strpos或者preg_match函数来对比就可以了。
判断浏览器类型:

&#60;?php echo $_SERVER[&#34;HTTP_USER_AGENT&#34;]; ?&#62;

判断浏览器语言:

&#60;?php echo $_SERVER[&#34;HTTP_ACCEPT_LANGUAGE&#34;]; ?&#62;

判断浏览器类型的具体程序如下:

&#60;?php
if(strpos($_SERVER[&#34;HTTP_USER_AGENT&#34;],&#34;MSIE 8.0&#34;))
echo &#34;Internet Explorer 8.0&#34;;
else if(strpos($_SERVER[&#34;HTTP_USER_AGENT&#34;],&#34;MSIE 7.0&#34;))
echo &#34;Internet Explorer 7.0&#34;;
else if(strpos($_SERVER[&#34;HTTP_USER_AGENT&#34;],&#34;MSIE 6.0&#34;))
echo &#34;Internet Explorer 6.0&#34;;
else if(strpos($_SERVER[&#34;HTTP_USER_AGENT&#34;],&#34;Firefox/3&#34;))
echo &#34;Firefox 3&#34;;
else if(strpos($_SERVER[&#34;HTTP_USER_AGENT&#34;],&#34;Firefox/2&#34;))
echo &#34;Firefox 2&#34;;
else if(strpos($_SERVER[&#34;HTTP_USER_AGENT&#34;],&#34;Chrome&#34;))
echo &#34;Google Chrome&#34;;
else if(strpos($_SERVER[&#34;HTTP_USER_AGENT&#34;],&#34;Safari&#34;))
echo &#34;Safari&#34;;
else if(strpos($_SERVER[&#34;HTTP_USER_AGENT&#34;],&#34;Opera&#34;))
echo &#34;Opera&#34;;
else echo $_SERVER[&#34;HTTP_USER_AGENT&#34;];
?&#62;

判断浏览器语言的具体程序如下:

&#60;?php
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 4); //只取前4位，这样只判断最优先的语言。如果取前5位，可能出现en,zh的情况，影响判断。
if (preg_match(&#34;/zh-c/i&#34;, $lang))
echo &#34;简体中文&#34;;
else if (preg_match(&#34;/zh/i&#34;, $lang))
echo &#34;繁體中文&#34;;
else if (preg_match(&#34;/en/i&#34;, $lang))
echo &#34;English&#34;;
else if (preg_match(&#34;/fr/i&#34;, $lang))
echo [...]]]></description>
			<content:encoded><![CDATA[<p>用php语言来判断浏览器类型其实很简单。<br />
因为浏览器在和服务器连接时候都会先发送一些包含自己信息的内容（浏览器类型、语言啦）。</p>
<p>这里我们主要分析的是_SERVER["HTTP_USER_AGENT"](浏览器类型)和_SERVER["HTTP_ACCEPT_LANGUAGE"](浏览器语言)。</p>
<p>我们所要做的就是把这些内容读出来，然后用strpos或者preg_match函数来对比就可以了。</p>
<p>判断浏览器类型:</p>
<pre class="brush: php; light: true;">
&lt;?php echo $_SERVER[&quot;HTTP_USER_AGENT&quot;]; ?&gt;
</pre>
<p>判断浏览器语言:</p>
<pre class="brush: php; light: true;">
&lt;?php echo $_SERVER[&quot;HTTP_ACCEPT_LANGUAGE&quot;]; ?&gt;
</pre>
<p>判断浏览器类型的具体程序如下:</p>
<pre class="brush: php;">
&lt;?php
if(strpos($_SERVER[&quot;HTTP_USER_AGENT&quot;],&quot;MSIE 8.0&quot;))
echo &quot;Internet Explorer 8.0&quot;;
else if(strpos($_SERVER[&quot;HTTP_USER_AGENT&quot;],&quot;MSIE 7.0&quot;))
echo &quot;Internet Explorer 7.0&quot;;
else if(strpos($_SERVER[&quot;HTTP_USER_AGENT&quot;],&quot;MSIE 6.0&quot;))
echo &quot;Internet Explorer 6.0&quot;;
else if(strpos($_SERVER[&quot;HTTP_USER_AGENT&quot;],&quot;Firefox/3&quot;))
echo &quot;Firefox 3&quot;;
else if(strpos($_SERVER[&quot;HTTP_USER_AGENT&quot;],&quot;Firefox/2&quot;))
echo &quot;Firefox 2&quot;;
else if(strpos($_SERVER[&quot;HTTP_USER_AGENT&quot;],&quot;Chrome&quot;))
echo &quot;Google Chrome&quot;;
else if(strpos($_SERVER[&quot;HTTP_USER_AGENT&quot;],&quot;Safari&quot;))
echo &quot;Safari&quot;;
else if(strpos($_SERVER[&quot;HTTP_USER_AGENT&quot;],&quot;Opera&quot;))
echo &quot;Opera&quot;;
else echo $_SERVER[&quot;HTTP_USER_AGENT&quot;];
?&gt;
</pre>
<p>判断浏览器语言的具体程序如下:</p>
<pre class="brush: php;">
&lt;?php
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 4); //只取前4位，这样只判断最优先的语言。如果取前5位，可能出现en,zh的情况，影响判断。
if (preg_match(&quot;/zh-c/i&quot;, $lang))
echo &quot;简体中文&quot;;
else if (preg_match(&quot;/zh/i&quot;, $lang))
echo &quot;繁體中文&quot;;
else if (preg_match(&quot;/en/i&quot;, $lang))
echo &quot;English&quot;;
else if (preg_match(&quot;/fr/i&quot;, $lang))
echo &quot;French&quot;;
else if (preg_match(&quot;/de/i&quot;, $lang))
echo &quot;German&quot;;
else if (preg_match(&quot;/jp/i&quot;, $lang))
echo &quot;Japanese&quot;;
else if (preg_match(&quot;/ko/i&quot;, $lang))
echo &quot;Korean&quot;;
else if (preg_match(&quot;/es/i&quot;, $lang))
echo &quot;Spanish&quot;;
else if (preg_match(&quot;/sv/i&quot;, $lang))
echo &quot;Swedish&quot;;
else echo $_SERVER[&quot;HTTP_ACCEPT_LANGUAGE&quot;];
?&gt;
</pre>
<p>这是根据上面的代码做出来的一个小程序:<br />
<a href="http://www.znsunimage.com/Download/test.php" title="http://www.znsunimage.com/Download/test.php" target="_blank">www.znsunimage.com/Download/test.php</a><br />
判断浏览器类型主要是靠分析_SERVER["HTTP_USER_AGENT"]的内容，而分析浏览器语言则是分析_SERVER["HTTP_ACCEPT_LANGUAGE"]。</p>
	<p></p>
	<hr noshade style="margin:0;height:1px" />
	<p>&copy; SUN for <a href="http://blog.znsunimage.com">徘徊在玻璃之城</a>, 2007. |
	  <a href="http://blog.znsunimage.com/2007/03/507/php-judgement-browser-type-and-language-system">Permalink</a> |
	  <a href="http://blog.znsunimage.com/category/tech" title="View all posts in 与时俱进" rel="category tag">与时俱进</a> | 
	  <a href="http://blog.znsunimage.com/2007/03/507/php-judgement-browser-type-and-language-system#comments">2 comments</a></p> ]]></content:encoded>
			<wfw:commentRss>http://blog.znsunimage.com/2007/03/507/php-judgement-browser-type-and-language-system/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.406 seconds -->
<!-- Cached page served by WP-Cache -->
