<?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>Tairan&#039;s Story &#187; Mobile</title>
	<atom:link href="http://www.tairan.net/index.php/tag/mobile/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tairan.net</link>
	<description>「知之真切笃实处即是行，行之明觉精察处即是知，知行工夫不可离。」</description>
	<lastBuildDate>Fri, 02 Dec 2011 08:08:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>如何识别手机浏览器信息</title>
		<link>http://www.tairan.net/index.php/2010/04/16/how-to-identify-mobile-browser/</link>
		<comments>http://www.tairan.net/index.php/2010/04/16/how-to-identify-mobile-browser/#comments</comments>
		<pubDate>Fri, 16 Apr 2010 13:05:29 +0000</pubDate>
		<dc:creator>Daniel Wang</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[实践手札]]></category>
		<category><![CDATA[我的声音]]></category>
		<category><![CDATA[Browser]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.tairan.net/?p=802</guid>
		<description><![CDATA[想作一个网站，根据不同的访问者提供不同的显示模板，如适合手机的模板，适合PC浏览器的模板。 从哪里识别访问者的信息，以及如何识别呢？ 依据 HTTP 协议，客户端浏览网页的时候会提供一些信息给服务器端。下面是PC浏览器访问时的 $_SERVER 的 dump 信息。 &#40;array&#41; Array &#40; &#91;ALL_HTTP&#93; =&#62; HTTP_CACHE_CONTROL:max-age=0 HTTP_CONNECTION:keep-alive HTTP_CONTENT_LENGTH:0 HTTP_ACCEPT:application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 HTTP_ACCEPT_CHARSET:ISO-8859-1,utf-8;q=0.7,*;q=0.3 HTTP_ACCEPT_ENCODING:gzip,deflate,sdch HTTP_ACCEPT_LANGUAGE:en-US,en;q=0.8 HTTP_COOKIE:__utmz=259664206.1262318873.1.1.utmcsr=google&#124;utmccn=(organic)&#124;utmcmd=organic&#124;utmctr=51xna; __utma=259664206.724256099.1262318873.1262318873.1262318873.1 HTTP_HOST:www.51xna.com HTTP_USER_AGENT:Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.9 Safari/533.2 &#160; [HTTPS] =&#62; off [SCRIPT_NAME] =&#62; /private/Kohana/index.php [HTTP_COOKIE] =&#62; __utmz=259664206.1262318873.1.1.utmcsr=google&#124;utmccn=(organic)&#124;utmcmd=organic&#124;utmctr=51xna; __utma=259664206.724256099.1262318873.1262318873.1262318873.1 [AUTH_PASSWORD] =&#62; [AUTH_TYPE] =&#62; [AUTH_USER] =&#62; [CONTENT_LENGTH] =&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>想作一个网站，根据不同的访问者提供不同的显示模板，如适合手机的模板，适合PC浏览器的模板。</p>
<p> 从哪里识别访问者的信息，以及如何识别呢？</p>
<p>依据 HTTP 协议，客户端浏览网页的时候会提供一些信息给服务器端。下面是PC浏览器访问时的 <a href="http://cn.php.net/manual/en/reserved.variables.server.php" target="_blank">$_SERVER</a> 的 dump 信息。</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">Array</span>
<span style="color: #009900;">&#40;</span>
    <span style="color: #009900;">&#91;</span>ALL_HTTP<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> HTTP_CACHE_CONTROL<span style="color: #339933;">:</span>max<span style="color: #339933;">-</span>age<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span>
HTTP_CONNECTION<span style="color: #339933;">:</span>keep<span style="color: #339933;">-</span>alive
HTTP_CONTENT_LENGTH<span style="color: #339933;">:</span><span style="color: #cc66cc;">0</span>
HTTP_ACCEPT<span style="color: #339933;">:</span>application<span style="color: #339933;">/</span>xml<span style="color: #339933;">,</span>application<span style="color: #339933;">/</span>xhtml<span style="color: #339933;">+</span>xml<span style="color: #339933;">,</span>text<span style="color: #339933;">/</span>html<span style="color: #339933;">;</span>q<span style="color: #339933;">=</span><span style="color:#800080;">0.9</span><span style="color: #339933;">,</span>text<span style="color: #339933;">/</span>plain<span style="color: #339933;">;</span>q<span style="color: #339933;">=</span><span style="color:#800080;">0.8</span><span style="color: #339933;">,</span>image<span style="color: #339933;">/</span>png<span style="color: #339933;">,*</span><span style="color: #666666; font-style: italic;">/*;q=0.5
HTTP_ACCEPT_CHARSET:ISO-8859-1,utf-8;q=0.7,*;q=0.3
HTTP_ACCEPT_ENCODING:gzip,deflate,sdch
HTTP_ACCEPT_LANGUAGE:en-US,en;q=0.8
HTTP_COOKIE:__utmz=259664206.1262318873.1.1.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=51xna; __utma=259664206.724256099.1262318873.1262318873.1262318873.1
HTTP_HOST:www.51xna.com
HTTP_USER_AGENT:Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.9 Safari/533.2
&nbsp;
    [HTTPS] =&gt; off
    [SCRIPT_NAME] =&gt; /private/Kohana/index.php
    [HTTP_COOKIE] =&gt; __utmz=259664206.1262318873.1.1.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=51xna; __utma=259664206.724256099.1262318873.1262318873.1262318873.1
    [AUTH_PASSWORD] =&gt; 
    [AUTH_TYPE] =&gt; 
    [AUTH_USER] =&gt; 
    [CONTENT_LENGTH] =&gt; 0
    [CONTENT_TYPE] =&gt; 
    [PATH_TRANSLATED] =&gt; g:\wwwroot\51xna.com\wwwroot\mobile\index
    [QUERY_STRING] =&gt; 
    [REMOTE_ADDR] =&gt; 221.227.130.23
    [REMOTE_HOST] =&gt; 221.227.130.23
    [REMOTE_USER] =&gt; 
    [REQUEST_METHOD] =&gt; GET
    [SERVER_NAME] =&gt; www.51xna.com
    [SERVER_PORT] =&gt; 80
    [SERVER_PROTOCOL] =&gt; HTTP/1.1
    [SERVER_SOFTWARE] =&gt; Microsoft-IIS/6.0
    [APPL_MD_PATH] =&gt; /LM/w3svc/798/ROOT
    [APPL_PHYSICAL_PATH] =&gt; g:\wwwroot\51xna.com\wwwroot\
    [INSTANCE_ID] =&gt; 798
    [INSTANCE_META_PATH] =&gt; /LM/W3SVC/798
    [LOGON_USER] =&gt; 
    [REQUEST_URI] =&gt; /private/Kohana/index.php/mobile/index
    [URL] =&gt; /private/Kohana/index.php/mobile/index
    [SCRIPT_FILENAME] =&gt; g:\wwwroot\51xna.com\wwwroot\private\Kohana\index.php
    [ORIG_PATH_INFO] =&gt; /private/Kohana/index.php/mobile/index
    [PATH_INFO] =&gt; /mobile/index
    [ORIG_PATH_TRANSLATED] =&gt; g:\wwwroot\51xna.com\wwwroot\private\Kohana\index.php\mobile\index
    [DOCUMENT_ROOT] =&gt; g:\wwwroot\51xna.com\wwwroot
    [PHP_SELF] =&gt; /private/Kohana/index.php
    [HTTP_CACHE_CONTROL] =&gt; max-age=0
    [HTTP_CONNECTION] =&gt; keep-alive
    [HTTP_CONTENT_LENGTH] =&gt; 0
    [HTTP_ACCEPT] =&gt; application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/</span><span style="color: #339933;">*;</span>q<span style="color: #339933;">=</span><span style="color:#800080;">0.5</span>
    <span style="color: #009900;">&#91;</span>HTTP_ACCEPT_CHARSET<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> ISO<span style="color: #339933;">-</span><span style="color: #cc66cc;">8859</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>utf<span style="color: #339933;">-</span><span style="color: #cc66cc;">8</span><span style="color: #339933;">;</span>q<span style="color: #339933;">=</span><span style="color:#800080;">0.7</span><span style="color: #339933;">,*;</span>q<span style="color: #339933;">=</span><span style="color:#800080;">0.3</span>
    <span style="color: #009900;">&#91;</span>HTTP_ACCEPT_ENCODING<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> gzip<span style="color: #339933;">,</span>deflate<span style="color: #339933;">,</span>sdch
    <span style="color: #009900;">&#91;</span>HTTP_ACCEPT_LANGUAGE<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> en<span style="color: #339933;">-</span>US<span style="color: #339933;">,</span>en<span style="color: #339933;">;</span>q<span style="color: #339933;">=</span><span style="color:#800080;">0.8</span>
    <span style="color: #009900;">&#91;</span>HTTP_HOST<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> www<span style="color: #339933;">.</span>51xna<span style="color: #339933;">.</span>com
    <span style="color: #009900;">&#91;</span>HTTP_USER_AGENT<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Mozilla<span style="color: #339933;">/</span><span style="color:#800080;">5.0</span> <span style="color: #009900;">&#40;</span>X11<span style="color: #339933;">;</span> U<span style="color: #339933;">;</span> Linux i686<span style="color: #339933;">;</span> en<span style="color: #339933;">-</span>US<span style="color: #009900;">&#41;</span> AppleWebKit<span style="color: #339933;">/</span><span style="color:#800080;">533.2</span> <span style="color: #009900;">&#40;</span>KHTML<span style="color: #339933;">,</span> like Gecko<span style="color: #009900;">&#41;</span> Chrome<span style="color: #339933;">/</span>5<span style="color: #339933;">.</span>0<span style="color: #339933;">.</span>342<span style="color: #339933;">.</span>9 Safari<span style="color: #339933;">/</span><span style="color:#800080;">533.2</span>
    <span style="color: #009900;">&#91;</span>REQUEST_TIME<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1271408243</span>
    <span style="color: #009900;">&#91;</span>argv<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
        <span style="color: #009900;">&#40;</span>
        <span style="color: #009900;">&#41;</span>
&nbsp;
    <span style="color: #009900;">&#91;</span>argc<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span>
<span style="color: #009900;">&#41;</span></pre></div></div>

<p>通常我们可以在HTTP_USER_AGENT中找到识别信息，其中PC浏览器的HTTP_USER_AGENT信息最全，很容易根据关键字来识别如&#8217;Chrome&#8217;, &#8216;Firefox&#8217; 等，部分手机浏览器也可以可以通过 &#8216;Windows Mobile&#8217;, &#8216;Windows Phone&#8217;, &#8216;SymbianOS&#8217;, &#8216;Nokia&#8217;, &#8216;Opera Mobi&#8217;, &#8216;Android&#8217;等关键字识别，这里有一个手机HTTP_USER_AGENT识别列表<a href="http://www.zytrax.com/tech/web/mobile_ids.html" target="_blank">http://www.zytrax.com/tech/web/mobile_ids.html</a>。但是有些手机上的浏览器并不提供HTTP_USER_AGENT信息。</p>
<p>如今的智能手机大多都支持 XHTML 格式浏览，我们可以通过 HTTP_ACCEPT 来识别手机是否支持 XHTML 格式浏览。这里识别的关键字主要是 &#8216;application/xhtml+xml&#8217;。</p>
<p>另外还有一种识别方式，通过查找用户的上网方式，通常手机用户走的是 GPRS 路线，但是这中识别方式并不可靠，可以作为一种辅助识别手段。</p>
<p>对于只支持 WML 的手机目前我还没有解决，一些非智能手机在访问网站时会提示&#8221;不支持所访问的网站&#8221;。开始我以为是返回信息的问题，当我把返回信息严格按照WML格式输出时问题依然存在。不知道这种手机是通过什么方式访问互联网的。</p>
<p>为所有用户提供不同的定制服务是一件不可能的完成任务，支持大多数就好。完美主义总是很浪费时间。</p>
<p>最后感谢各位提供手机访问信息的童鞋们，让你们忍受在手机上输入如此之长的URL，实在辛苦！</p>
<hr />
<p><small>© Daniel Wang for <a href="http://www.tairan.net">Tairan&#039;s Story</a>, 2010. |
<a href="http://www.tairan.net/index.php/2010/04/16/how-to-identify-mobile-browser/">Permalink</a> |
<a href="http://www.tairan.net/index.php/2010/04/16/how-to-identify-mobile-browser/#comments">One comment</a> |
Add to
<a href="http://del.icio.us/post?url=http://www.tairan.net/index.php/2010/04/16/how-to-identify-mobile-browser/&title=如何识别手机浏览器信息">del.icio.us</a>
<br/>
Post tags: <a href="http://www.tairan.net/index.php/tag/browser/" rel="tag">Browser</a>, <a href="http://www.tairan.net/index.php/tag/mobile/" rel="tag">Mobile</a>, <a href="http://www.tairan.net/index.php/tag/php/" rel="tag">PHP</a><br/>
</small></p>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tairan.net/index.php/2010/04/16/how-to-identify-mobile-browser/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

