.

Mobile Detect PHP - Nhận biết thiết bị di động

Mobile Detect là bộ code PHP hoàn toàn miễn phí, bạn có thể sử dụng cho bất kỳ dự án website nào bạn muốn. 

Mobile Detect PHP - Nhận biết thiết bị di động
Cách sử dụng bộ code này cũng cực kỳ đơn giản, bên dưới là một số ví dụ cho bạn tham khảo khi tích hợp Mobile Detect vào dự án web của mình.
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
// Include and instantiate the class.
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
// Any mobile device (phones or tablets).
if ( $detect->isMobile() ) {
}
// Any tablet device.
if( $detect->isTablet() ){
}
// Exclude tablets.
if( $detect->isMobile() && !$detect->isTablet() ){
}
// Check for a specific platform with the help of the magic methods:
if( $detect->isiOS() ){
}
if( $detect->isAndroidOS() ){
}
// Alternative method is() for checking specific properties.
// WARNING: this method is in BETA, some keyword properties will change in the future.
$detect->is('Chrome');
$detect->is('iOS');
$detect->is('UC Browser');
// [...]
// Batch mode using setUserAgent():
$userAgents = array(
    'Mozilla/5.0 (Linux; Android 4.0.4; Desire HD Build/IMM76D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19',
    'BlackBerry7100i/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/103',
// [...]
);
foreach($userAgents as $userAgent){
    $detect->setUserAgent($userAgent);
    $isMobile = $detect->isMobile();
    $isTablet = $detect->isTablet();
// Use the force however you want.
}
// Get the version() of components.
// WARNING: this method is in BETA, some keyword properties will change in the future.
$detect->version('iPad'); // 4.3 (float)
$detect->version('iPhone'); // 3.1 (float)
$detect->version('Android'); // 2.1 (float)
$detect->version('Opera Mini'); // 5.0 (float)
// [...]
Với Mobile Detect bạn có thể nhận biết được người dùng đang sử dụng điện thoại di động hoặc máy tính bảng. Thậm chí bạn còn có thể biết được cụ thể là người dùng đang sử dụng điện thoại đang chạy hệ điều hành gì, hãng nào sản xuất và đang duyệt web bằng trình duyệt nào.


Công cụ này sẽ rất hữu ích nếu bạn muốn thiết kế giao diện web hiển thị khác nhau khi người dùng truy cập từ máy tính, điện thoại hoặc máy tính bảng. Bạn có thể sử dụng lại code này mà không cần phải bỏ ra nhiều thời gian để tự viết code bởi nó đang được tin dùng từ rất nhiều người.
Mobile Detect PHP - Nhận biết thiết bị di động Reviewed by Unknown on 05:45 Rating: 5

Không có nhận xét nào:

Phát triển bởi iZdesigner Team

Biểu mẫu liên hệ

Tên

Email *

Thông báo *

Được tạo bởi Blogger.