有一个基于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() |