index.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. $url = "/pc";
  3. if (is_mobile()) {
  4. $url = "/mobile";
  5. }
  6. /**
  7. * 是否为移动端
  8. */
  9. function is_mobile()
  10. {
  11. if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) {
  12. return true;
  13. }
  14. if (isset($_SERVER['HTTP_VIA'])) {
  15. return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
  16. }
  17. if (isset($_SERVER['HTTP_USER_AGENT'])) {
  18. $clientkeywords = array('nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp', 'sie-', 'philips', 'panasonic', 'alcatel', 'lenovo', 'iphone', 'ipod', 'blackberry', 'meizu', 'android', 'netfront', 'symbian', 'ucweb', 'windowsce', 'palm', 'operamini', 'operamobi', 'openwave', 'nexusone', 'cldc', 'midp', 'wap', 'mobile');
  19. if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
  20. return true;
  21. }
  22. }
  23. if (isset($_SERVER['HTTP_ACCEPT'])) {
  24. if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'textml') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'textml')))) {
  25. return true;
  26. }
  27. }
  28. return false;
  29. }
  30. ?>
  31. <!DOCTYPE html>
  32. <html lang="en">
  33. <head>
  34. <meta charset="UTF-8">
  35. <meta http-equiv="refresh" content="0;url=<?php echo $url; ?>">
  36. <title></title>
  37. </head>
  38. <body>
  39. </body>
  40. </html>