Maison  >  Article  >  développement back-end  >  判断访问者所用设备是iPhone、iPad或PC电脑的方法

判断访问者所用设备是iPhone、iPad或PC电脑的方法

WBOY
WBOYoriginal
2016-07-25 08:59:431791parcourir
复制代码

2、php实现

  1. //方法1

  2. $is_iPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad');
  3. //方法2

  4. $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
  5. $is_pc = (strpos($agent, 'windows nt')) ? true : false;
  6. $is_iphone = (strpos($agent, 'iphone')) ? true : false;
  7. $is_ipad = (strpos($agent, 'ipad')) ? true : false;
  8. if($is_pc){
  9. echo "PC机"; //by http://bbs.it-home.org
  10. }
  11. if($is_iphone){
  12. echo "iPhone";
  13. }
  14. if($is_ipad){
  15. echo "iPad";
  16. }
  17. ?>
复制代码

3、htaccess

  1. RewriteCond %{HTTP_USER_AGENT} ^.*iPad.*$
  2. RewriteRule ^(.*)$ http://ipad.jbxue.com [R=301]
复制代码

如果是 iPad 浏览器,跳转到 iPad 页面。



Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn