PHP code example of coercive / browser

1. Go to this page and download the library: Download coercive/browser 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/ */

    

coercive / browser example snippets


use Coercive\Utility\Browser

# Load instance
$browser = new Browser();

# Examples
echo $browser->browser()['name']
echo $browser->browser()['version']
echo $browser->os()
echo $browser->getAGENT()
echo $browser->getIP()

if($browser->mobile()) {}

if($browser->isClientIpInRange('range', /* current */)) {}
if($browser->isClientIpInRange('range', 'ip')) {}

# Mobile_Detect
# https://github.com/serbanghita/Mobile-Detect
$oBrowser->Mobile_Detect()

use Coercive\Utility\Browser

# Load instance
$ip = new Ip();

# Validate ip / cidr
if($ip->check('127.0.0.1')) {}
if($ip->check('127.0.0.1/32', true)) {}

# Cidr in range infos (start, end, subnet, wildcard, count...)
echo '<pre>';
var_dump($ip->cidrToRange('127.0.0.1/32'));
echo '</pre>';

# List all ips in range
echo '<pre>';
var_dump($ip->cidrToFullRange('127.0.0.1/32'));
echo '</pre>';

# Check if IP is in given domain list - with optional reverse check
if($ip->isIpMatchDomains('127.0.0.1', ['example.domain.com'], true)) {}

# Checking if a given ip belongs to given cidr list
if($ip->isInRange('127.0.0.1', ['127.0.0.1/27','127.0.0.1/64'])) {}