Home > php教程 > php手册 > body text

php判断是android还是ios还是wp的访问网站

WBOY
Release: 2016-06-13 09:02:49
Original
929 people have browsed it

php判断是android还是ios还是wp的访问网站

   下文来为各位整理一段php判断是android还是ios还是wp的访问网站例子,非常 的实用希望对各位朋友会有所帮助.

  在php中可以用$_SERVER['HTTP_USER_AGENT']来区分是android、ios还是wp的请求,具体可以用以下代码来实现:

  $userAgent = $_SERVER['HTTP_USER_AGENT'];

  if (preg_match("/(iPod|iPad|iPhone)/", $userAgent))

  {

  echo 'ios'; //IOS客户端

  }

  elseif (preg_match("/WP/", $userAgent))

  {

  echo 'wp'; //WinPhone客户端

  }

  elseif (preg_match("/android/i", $userAgent)) {

  echo 'android'; //android客户端

  }

  当然我也可以在网页头部加上一段js代码效果是一样的  

  这样只要是手机访问网站就会自动到了手机版本网站了

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template