Home >Backend Development >PHP Tutorial >How to determine whether the visitor's device is an iPhone, iPad, or PC

How to determine whether the visitor's device is an iPhone, iPad, or PC

WBOY
WBOYOriginal
2016-07-25 08:59:431874browse
复制代码

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 页面。



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn