你的站点有来自手机的访客吗?你的站点在手机浏览器下排版完美吗?
如果你有来自手机界面的访问者,你很可能需要将他们引导至一个不同的页面,一个特别为手机浏览器优化的界面。
1.在页面头部添加判断
通过PHP和浏览器头信息,我们可以轻松地实现将手机用户转向经过专门设计的WAP界面。我恰好使用了WP-T-WAP插件实现了界面的WAP化,WAP浏览的地址是http://nosame.net/wap。(你可以尝试浏览这个地址,它可以在电脑上被打开。真抱歉,我现在用的是MobilePress,没有演示了,MobilePress可以自动判断访问者的浏览器。)
我希望手机访客在打开http://nosame.net/地址时,自动导向http://nosame.net/wap。怎么办呢?

答案非常简单。
打开header.php文件。在第一行插入以下代码:
< ?php
$agent = $_SERVER['HTTP_USER_AGENT'];
if(strpos($agent,"NetFront") || strpos($agent,"iPhone") || strpos($agent,"MIDP-2.0") || strpos($agent,"Opera Mini") || strpos($agent,"UCWEB") || strpos($agent,"Android") || strpos($agent,"Windows CE") || strpos($agent,"SymbianOS"))
header("Location:http://nosame.net/wap");
?>
这段代码的含义是,当浏览器返回的UA信息为Opera Mini、UCWEB等内容时,将页面转向http://nosame.net/wap。
1.1 补充:增加手机浏览器的跳转提示
当你使用上面的方法设置跳转时,可能会遇到这种状况:手机访问者直接访问类似http://nosame.net/archive/xxx的子页面,而不是首页。这时,改判断语句仍然会执行命令,将手机访问者引导至手机界面的首页,使访客无法获取想要的信息。
怎么办呢?
你可以在这段语句之外再加入一个判断,只有在当前页面为首页时执行此命令。
在WordPress环境下这个判断的写法是
<?php if ( is_home() ) { ... }?>
那么全部的代码是:
<?php
$agent = $_SERVER['HTTP_USER_AGENT'];
if ( is_home() && ((strpos($agent,"NetFront") || strpos($agent,"iPhone") || strpos($agent,"MIDP-2.0") || strpos($agent,"Opera Mini") || strpos($agent,"UCWEB") || strpos($agent,"Android") || strpos($agent,"Windows CE") || strpos($agent,"SymbianOS")) )
header("Location:http://nosame.net/wap");
}
?>
这样我们又遇到一个问题:手机访问者在浏览子页面时,并不知道你提供了WAP界面,而你恰恰又很希望推销的你的WAP界面。
我们可以修改这个判断语句,让它不再直接跳转,而是在特定浏览器下显示提示信息,告诉手机用户可以转换至WAP界面浏览。
代码写法如下:
<?php
$agent = $_SERVER['HTTP_USER_AGENT'];
if(strpos($agent,"NetFront") || strpos($agent,"iPhone") || strpos($agent,"MIDP-2.0") || strpos($agent,"Opera Mini") || strpos($agent,"UCWEB") || strpos($agent,"Android") || strpos($agent,"Windows CE") || strpos($agent,"SymbianOS")) { ?>
<div id="mobile"><p>系统检测到您正在使用手机浏览器,您可以访问<a href="http://nosame.net/wap">移动界面</a>以获取更好的浏览体验。</p></div>
<?php } ?>
当然了,你可以综合这两种方法,让手机访客在访问首页时自动跳转,而访问其他界面时显示提示信息。
2.需要足够的手机浏览器UA信息
当浏览器访问页面时,它会向服务器提交一个标志字符,这段字符被称作UA(User Agent),他们看起来大概是这个样子:
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) )
是的,UA很长,甚至还包含了系统信息。但是当我们进行判断时,只需要核对最关键的字符。比如我需要判断当前用户是否使用了IE 8(我的确就是用的IE8),那么 在上面的判断语句中就应该写成strpos($agent,”MSIE 8.0″) 。
我准备了8种最常见的浏览器/平台分别是NetFront、iPhone、JAVA(MIDP-2.0)、Opera Mini、UCWEB、Android、Windows CE/Mobile、SymbianOS。就目前的状况来说,这8种平台已经包含了国内几乎全部的手机访客,当然,完整的手机浏览客户端列表不止这么多,我罗列一些:
2.0 MMP, 240×320, 400X240, AvantGo, BlackBerry, Blazer, Cellphone, Danger, DoCoMo, Elaine/3.0 EudoraWeb, Googlebot-Mobile, hiptop, IEMobile, KYOCERA/WX310K, LG/U990, MIDP-2., MMEF20, MOT-V, NetFront, Newt, Nintendo Wii, Nitro, // Nintendo DS Nokia, Opera Mini, Palm, PlayStation Portable, portalmmm, Proxinet, ProxiNet, SHARP-TQ-GX10, SHG-i900, Small, SonyEricsson, Symbian OS, SymbianOS, TS21i-10, UP.Browser, UP.Link, webOS, // Palm Pre, etc. Windows CE, WinWAP, YahooSeeker/M1A1-R2D2
你可以根据这个列表添加或替换上面的PHP判断语句。但是我仍然推荐我已经选好的8种平台,因为目前会使用手机浏览互联网——特别是个人博客的用户,基本上都是高端玩家。
另外你可以写一个简单的页面,用来判断你的手机UA
<?phpecho $_SERVER['HTTP_USER_AGENT']; ?>
保存为ua-test.php,上传至服务器,用你的手机访问这个页面。
3.如何通过工具创建WAP界面
当然,你可能还有一个问题,那就是无法创建WAP浏览界面——你使用的平台还没有WAP化插件。怎么办呢?
你可以使用MoFuse创建你的移动版博客,使用方法请参阅MoFuse为博客免费创建Wap版。MoFuse支持绑定子域名,这意味着你可以使用xxx.yorname.com来创造你的移动博客界面。写完之后才发现,MoFuse已经在收费了,而且很不便宜。
http://cn.feedm8.com/也提供类似的服务,他们将站点的RSS转换成手机可以阅读的界面。点击申请帐户,feedm8将会为你提供一个固定的手机浏览界面地址,你可以向你的手机访客推荐这个地址。feedm8提供的界面并不十分美观,而且它会在你的页面中加入广告(似乎有分成),关键是,这些都是免费的。

quwalce – Thank you, phxpftm.
回复
wnxxhgf – Thank you, zstfabp.
回复
July to August a airline united bankrupt a a toronto flight direct curacao to a cancer does diet cure a boulder co flowers elite a florist saybrook in ct old a flight missile demonstrations uk a tate general contractors arkansas a texas mortgage lenders second bankruptcy mortgages a
回复
actswjg – Thank you, cpqjdfd.
回复
uqstazd – Thank you, ypqlgux.
回复
comment5, ambien sleep driving, buy zolpidem, erythromycin solution, oral diflucan, Lexapro, amoxil 500, rimonabant, buy zithromax liquid, Valtrex,
回复
July to September a calcium carbonate dose for nursing dog a celebrex and norflex causing elevated bp a discount calcium carbonate a cefadroxil side effects a wellbutrin sr bupropion colorado a bupropion and ocd a buy Celadrin a
回复
hgjyzgb – Thank you, snknaed.
回复
orokelm – Thank you, qsuqyww.
回复
July to September a generic cialis and generic viagara a cephalexin and drug interactions a vioxx vs celebrex a cheap chrysin-xy a fluoroquinolones and chloroquine a
回复
azftnyo – Thank you, iqehkif.
回复
phttkph – Thank you, jknkqji.
回复
loving this website, good thing I stumbled it for you on stumble upon.
回复
comment4, antabuse disulfiram, Ultram, ambien, Zolpidem, order cialis, Cymbalta, cialis physical dependency, diflucan one, chances of getting pregnant on clomid, Adipex, alternatives to viagra, zimulti, brocho pack zithromax, Lipitor, levitra plus 400mg, accutane, effects of prednisone, aspirin ph, Xenical,
回复
krguenf – Thank you, whzmupy.
回复
gnsqayh – Thank you, wowigvf.
回复
July to September a clariton and allegra a cialis soft tab india a comparativo viagra cialis a suicidal thoughts citalopram a
回复
July to August a hawaii nets in camo a solutions neutrogena advanced acne a cheap vacation packages romantic a uk brokers car insurance a online florist an find a xna las flight to a in island dating rhode speed a wireless internet laptop modem a
回复
rifbgdk – Thank you, ejlwxow.
回复
ujigtkb – Thank you, bxrftdh.
回复
July to September a how much claritin for dogs a claritin tagamet herpes a claritin suidice a claritin for sinus congestion a 24 claritin d a
回复
khdurpm – Thank you, fkgyezs.
回复
comment4, acomplia brand only, propranolol, klonopin urination, wholesale alprazolam, buy online viagra, retin a micro before and after picture, cytotechnology hospital in in job ny state, discount pharmacy purchase zithromax, Valtrex,
回复
dyumioc – Thank you, xwvvlsm.
回复
July to September a tennenbaum ny dentist roslyn m a used or mcminnville car a snow resorts in depth a dentist tifton in ga a oral roulette russian a insurance cars dodge comparison a tour manassas flight over helicopter a soros policy security institute george homeland a car used sale hauler for a
回复
dddetqj – Thank you, imsshmc.
回复
mpvimey – Thank you, yieguna.
回复
Good topic for making an effective dissertation. . . . . .
回复
ittshyr – Thank you, dtkqilv.
回复
qbssrtq – Thank you, lyvzjle.
回复
July to August a movers mobile chris hall ca a ambre studio sonoma noir scent a perfect a steak cooking a fragrance innocent angel review a dentistry sedation fremont a sprint ringtones free phones a surgical nj freehold associates endo a dentists francisco california biological san a math national for teaching conference a
回复
Glad i recently came across this site, will be sure to book mark it so i can come by often.
回复
This blog is highly informatics, crisp and clear. Here everything has been described in systematic manner so that reader could get maximum information and learn many things. This is one of the best blogs I have read. http://www.mappingminds.in
回复
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 7680 bytes) in /DISK2/WWW/nosame.net/www/wp-includes/kses.php(1031) : runtime-created function on line 1