PHP Classes
elePHPant
Icontem

PHP Browser Helper Class: Check and display the details of the user browser

Recommend this page to a friend!
  Info   View files Documentation   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2019-05-19 (4 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 75 All time: 9,429 This week: 300Up
Version License PHP version Categories
browserhelperclass 1.0Custom (specified...5HTTP, PHP 5
Description Author

This class can check and display the details of the user browser.

It can check the HTTP user agent sent by the browser and extract details like the browser type and version, operating system type

The class can also display the browser information details in a Web page.

It can also compare the browser version and determine if it is less, equal, or more than a given version number.

Name: aad pouw <contact>
Classes: 1 package by
Country: The Netherlands The Netherlands
Age: 62
All time rank: 4262103 in The Netherlands The Netherlands
Week rank: 714 Up21 in The Netherlands The Netherlands Up

 

Details

<h2>Subject: BrowserHelper</h2> <p>Based on and Credits to: <span>james2doyle/getBrowser.php</span> </p>

<h3>Summery:</h3> <ul> <li>Language:<span>PHP</span></li> <li>Version:<span>5+</span></li> <li>Developed on:<span>7.3</span></li> <li>Purpose:<span> A helper class to obtain info and to perform actions upon the user's browser</span></li> </ul>

<h3 style="margin-bottom:-15px">Capabilities:</h3> <ul> <li>Obtain and print the user's user agent info:<span style="color: blue; font-size: 0.9em"><strong>getBrowserInfo()</strong></span> <h4 style="margin-top:0 ; margin-botom:0">Options</h4> <ul style="margin-top:0">

    <li style="padding-top:-20px">Printing in HTML:<span style="color: blue; font-size: 0.9em"><strong>setUseHtml(true)</strong></span><div>This is an ul(class 'browser-details-ul') / li(class 'browser-detail-li') setup!</div></li>   
    <li>Adding a parent element:<span style="color: blue; font-size: 0.9em">eg: <strong>setWrapper('div')</strong></span></li>   
    <li>Adding attributes on that element:<span style="color: blue;  font-size: 0.9em">eq: <strong>setAttribute('class="foo" style="css:rules"')</strong></span></li>   

</ul> </li> <li style="margin-top:0;">Perform actions based on user's platfom:<span style="color: blue; font-size: 0.9em">eg:<strong>IsPlatform('Mac')</strong></span></li> <li>Perform actions based on user's browser:<span style="color: blue; font-size: 0.9em">eg:<strong>IsUserBrowser('Safari')</strong></span></li> <li>Perform actions based on user's browser & version number 'this is with built in comparison':<span style="color: blue; font-size: 0.9em">eg:<strong>IsVersion('Equal', '10.0')</strong></span> <div>The options are:</div> <ul style="color:olivedrab"> <li>Equal</li> <li>NotEqual</li> <li>GreaterThan</li> <li>LessThan</li> <li>GreaterThanOrEqualTo</li> <li>LessThanOrEqualTo</li> </ul> </li> </ul>

<h3>Howto:</h3>

<?php

require_once('path/to/BrowserHelper.php');
// in case of namespaced

use path\to\BrowserHelper;


//in a function eg:
function print_useragent(){
    $browser = new BrowserHelper();
    $this->_browser = new BrowserHelper();
        // 
        if($browser->IsPlatform('Mac')): 
            // your actions for this platform
        else:
            // your actions for the other platforms
        endif;
        
        if($browser->IsUserBrowser('Chrome')): 
            // your actions for this browser
        else:
            // your actions for the other browsers
        endif;
        
        if($browser->IsUserBrowser('Chrome') and $browser->IsVersion('LessThanOrEqualTo', '70.0')): 
           // your actions for this browser and depending on the version number
        // if more comparisons
        elseif($browser->IsUserBrowser('Chrome') and $browser->IsVersion('LessThanOrEqualTo', '60.0')):   
            //second step, your actions for this browser and depending on the version number
        else:
           // your actions for the other browsers and version numbers
        endif;
    /
     * this options are chainable!
    */
    //if you want it printed in html
    $browser->setUseHtml(true);
    //if you want a parent element eg:
    $browser->setWrapper('div');
    //if you want add attributes to the parent element eg:
    $browser->setAttribute('class="foo" style="css:rules"')
    //echo or return  $browser->getBrowserInfo();
}
    
// in a class
protected $_browser;
// within a class function eg:
public function __construct(){
    $this->_browser = new BrowserHelper();
    // 
    if($this->_browser->IsPlatform('Mac')): 
        // your actions for this platform
    else:
        // your actions for the other platforms
    endif;
    
    if($this->_browser->IsUserBrowser('Chrome')): 
        // your actions for this browser
    else:
        // your actions for the other browsers
    endif;
    
    if($this->_browser->IsUserBrowser('Chrome') and $this->_browser->IsVersion('LessThanOrEqualTo', '70.0')): 
       // your actions for this browser and depending on the version number
    // if more comparisons
    elseif($this->_browser->IsUserBrowser('Chrome') and $this->_browser->IsVersion('LessThanOrEqualTo', '60.0')):   
       //second step, your actions for this browser and depending on the version number
    else:
       // your actions for the other browsers and version numbers
    endif;
}

public function print_useragent(){
    /
     * this options are chainable!
    */
    //if you want it printed in html
    $this->_browser->setUseHtml(true);
    //if you want a parent element eg:
    $this->_browser->setWrapper('div');
    //if you want add attributes to the parent element eg:
    $this->_browser->setAttribute('class="foo" style="css:rules"')
    //echo or return  $this->_browser->getBrowserInfo();
    
}

<h4 style="margin-bottom:-15px">About me.</h4> <p>I'm not a php expert and just have a basic knowledge about it. I usually get there by looking up examples, making mistakes, learning and above all with persistence. Therefor constructive critics are alway welcome. </p>

<h5 style="margin-top:-10px;margin-bottom:-15px">My website: https://www.aadswebdesign.nl</h5> <h5 style="margin-bottom:-15px">In progress.</h5> <p> This site is in progress and there is still a lot to be done. Because I have limited time for that, the progrees is at a slow pace. At the first page I have an html print of browserinfo. <?p>

  Files folder image Files  
File Role Description
Files folder imagesrc (1 file)
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file Readme.md Doc. Read me

  Files folder image Files  /  src  
File Role Description
  Plain text file BrowserHelper.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:75
This week:0
All time:9,429
This week:300Up