Use PHP built-in function get_browser () to determine if it is a mobile browser

Source: Internet
Author: User

get_browser - Gets the functionality that the browser has. This function browscap.ini attempts to detect the functionality of a user's browser by locating the browser information in the file.

Due to the amount of license, PHP does not provide browser function files, you can get browser function files from Browscap, you can download Php_browscap.ini files in http://browscap.org/.

After download, it needs to be set in PHP.ini (Win):

Browscap=d:\wamp\bin\php\php5. 5.12\browscap.ini

or (under Linux)

Browscap=/usr/local/php/lib/php/browscap.ini

You can now print out the Get_browser () in the PHP file

Var_dump (Get_browser ());

Output:

Object(StdClass) #1( the) {  ["Browser_name_regex"]=>string(101)"~^mozilla/5\.0 \ (. *windows nt 10\.0.*\) applewebkit/.* \ (khtml, like gecko\) chrome/49\: *safari/.*$~"  ["Browser_name_pattern"]=>string( -)"mozilla/5.0 (*windows NT 10.0*) applewebkit/* (khtml, like Gecko) chrome/49.*safari/*"  ["Parent"]=>string( One)"Chrome 49.0"  ["Platform"]=>string(5)"Win10"  ["Comment"]=>string( One)"Chrome 49.0"  ["Browser"]=>string(6)"Chrome"  ["Browser_maker"]=>string(Ten)"Google INC"  ["version"]=>string(4)"49.0"  ["majorver"]=>string(2)" the"  ["Device_type"]=>string(7)"Desktop"  ["Device_pointing_method"]=>string(5)"Mouse"  ["Minorver"]=>string(1)"0"  ["IsMobileDevice"]=>string(0)""  ["Istablet"]=>string(0)""  ["crawler"]=>string(0)""}

The following code can be used to determine whether a mobile browser:

<? PHP $ismobiledevice Get_browser ()IsMobileDevice; if ($ismobiledevice) {    // mobile device- else  {     // PC-Side }

Reference:

<php cookbook>,3rd

Use PHP built-in function get_browser () to determine if it is a mobile browser

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.