PHP code example of hocvt / browser-detect

1. Go to this page and download the library: Download hocvt/browser-detect library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hocvt / browser-detect example snippets


use Browser;

// Determine the user's device type is simple as this:
$isMobile = Browser::isMobile();
Browser::isTablet();
Browser::isDesktop();

if (Browser::isMobile()) {
  // Redirect to the mobile version of the site.
}

// Every wondered if it is a bot who loading Your page?
if (Browser::isBot()) {
    echo 'No need to wonder anymore!';
}

// Check for common vendors.
if (Browser::isFirefox() || Browser::isOpera()) {
    $response .= '<script src="firefox-fix.js"></script>';
}

// Sometimes You may want to serve different content based on the OS.
if (Browser::isAndroid()) {
    $response .= '<a>Install our Android App!</a>';
} elseif (Browser::isMac() && Browser::isMobile()) {
    $response .= '<a>Install our iOS App!</a>';
}

use hisorange\BrowserDetect\Parser as Browser;

if (Browser::isLinux()) {
    // Works as well!
}

use hisorange\BrowserDetect\Parser;

$browser = new Parser(null, null, [
    'cache' => [
        'interval' => 86400 // This will override the default configuration.
    ]
]);

$result = $browser->detect();

// When You call the detect function You will get a result object, from the current user's agent.
$result = Browser::detect();

// If You wanna get browser details from a user agent other than the current user call the parse function.
$result = Browser::parse('Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14');
sh
# Will copy a config file to ~/app/config/browser-detect.php
php artisan vendor:publish