|
本帖最后由 demo 于 2014-3-3 06:19 编辑
- Create two folders in your server called "mobile" and "pc", each containing the respective versions of your site.
- Copy the code below.
- Replace the red links with your Mobile and PC destinations.
- Save and upload as your index.php
Code:
- <?php
- $mobile_browser = '0';
- if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone)/i',
- strtolower($_SERVER['HTTP_USER_AGENT']))){
- $mobile_browser++;
- }
- if((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml')>0) or
- ((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE'])))){
- $mobile_browser++;
- }
- $mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4));
- $mobile_agents = array(
- 'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',
- 'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
- 'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
- 'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
- 'newt','noki','oper','palm','pana','pant','phil','play','port','prox',
- 'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
- 'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
- 'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
- 'wapr','webc','winw','winw','xda','xda-');
- if(in_array($mobile_ua,$mobile_agents)){
- $mobile_browser++;
- }
- if (strpos(strtolower($_SERVER['ALL_HTTP']),'OperaMini')>0) {
- $mobile_browser++;
- }
- if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows')>0) {
- $mobile_browser=0;
- }
- if($mobile_browser>0){
- header('Location: <font color="Red"><b>http://YourSite.mobi/mobile</b></font>');
- } else {
- header('Location: <font color="Red"><b>http://YourSite.mobi/pc</b></font>');
- }
-
- ?>
复制代码 More info.
ALTERNATIVES:
I've created a WURFL zipped file that contains everything you need, and makes it incredibly easy, for your .mobi site to detect whether the visitor is on a PC or a Mobile and to redirect accordingly.
Simply download the WURFL.zip file below, extract the files, open readmefirst.txt, and follow the 5 simple steps. Couldn't be easier!
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
×
|