Desktop version or Mobile version?


/ Published in: PHP
Save to your folder(s)

Not is mine, I found it online, I just found it and modified it\r\n\r\nI do not remember where I took if anyone knows the original URL I will include it


Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. $mobile_browser = '0';
  4.  
  5. if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|android|ipod|iphone|ipad|safari.mobile)/i', strtolower($_SERVER['HTTP_USER_AGENT']))) {
  6. $mobile_browser++;
  7. }
  8.  
  9. if((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml')>0) or ((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE'])))) {
  10. $mobile_browser++;
  11. }
  12.  
  13. $mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4));
  14. $mobile_agents = array(
  15. 'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',
  16. 'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
  17. 'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
  18. 'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
  19. 'newt','noki','oper','palm','pana','pant','phil','play','port','prox',
  20. 'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
  21. 'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
  22. 'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
  23. 'wapr','webc','winw','winw','xda','xda-');
  24.  
  25. if(in_array($mobile_ua,$mobile_agents)) {
  26. $mobile_browser++;
  27. }
  28.  
  29. if (strpos(strtolower($_SERVER['ALL_HTTP']),'OperaMini')>0) {
  30. $mobile_browser++;
  31. }
  32.  
  33. if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows')>0) {
  34. $mobile_browser=0;
  35. }
  36.  
  37. if($mobile_browser>0) {
  38. // version mobile
  39. header("Location: mobile/source/main/index.html");
  40. }
  41. else {
  42. // version normal
  43. include 'normal.html';
  44. }
  45.  
  46. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.