用PHP检测用户是用手机(Mobile)还是电脑(PC)访问网站

有一个基于MIT License协议开源的PHP文件可以很方便地检测用户到底是用手机(Mobile)还是电脑(PC)访问网站。

下载地址为:http://code.google.com/p/php-mobile-detect/

 Description

      Mobile_Detect is a lightweight PHP class for detecting mobile devices. It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment. Mobile_Detect is a simple PHP class for easy detection of the most popular mobile platforms: Android, iPhone, Blackberry, Opera Mini, Palm, Windows Mobile, as well as generic ones.

Basic Usage

Include and instantiate the class:

?
1
2
include ( "Mobile_Detect.php" );
$detect = new Mobile_Detect();

Check for a specific platform:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
if ( $detect ->isAndroid()) {
// code to run for the Google Android platform
}
  //Available methods are
  isAndroid(),
  isAndroidtablet(),
  isIphone(),
  isIpad(),
  isBlackberry(),
  isBlackberrytablet(),
  isPalm(),
  isWindowsphone(),
  isWindows(),
isGeneric().
/**
  * Alternatively, if you are only interested in checking to see
  * if the user is using a mobile device, without caring
  * for specific platform:
  */
if ( $detect ->isMobile()) {
     // any mobile platform
     }
// Details
// 1、Use isMobile() for detecting any kind of mobile device
// 2、Use isTablet() for detecting tablet devices
// Further detection You can detect specific devices
// by using case-insensitive pseudo-methods.
isiPhone()
isBlackBerry()
isHTC()
isNexus()
isDellStreak()
isMotorola()
isSamsung()
isSony()
isAsus()
isPalm()
isBlackBerryTablet()
isiPad()
isKindle()
isSamsungTablet()
isMotorolaTablet()
isAsusTablet()
isAndroidOS()
isBlackBerryOS()
isPalmOS()
isSymbianOS()
isWindowsMobileOS()
isiOS()
isChrome()
isDolfin()
isOpera()
isSkyfire()
isIE()
isFirefox()
isBolt()
isTeaShark()
isBlazer()
isSafari()
isMidori()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值