PHP Classes

PHP User Agent Parser: Parse the user agent string to get browser details

Recommend this page to a friend!
  Info   View files Example   View files View files (9)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 63%Total: 480 This week: 1All time: 5,945 This week: 99Up
Version License PHP version Categories
php-useragent 1.0.2Custom (specified...5HTTP, PHP 5, Parsers
Description 

Author

This class can parse the user agent string to get browser details.

It takes the user agent string of the browser eventually accessing the current site and parses it to extract several details about the user browser and computer.

The class stores the browser details in variable for the browser name and version, operating system name and version, and mobile device name if it is a mobile browser.

Picture of Ahmed Saad
  Performance   Level  
Name: Ahmed Saad <contact>
Classes: 10 packages by
Country: Egypt Egypt
Age: ???
All time rank: 214621 in Egypt Egypt
Week rank: 111 Up1 in Egypt Egypt Up
Innovation award
Innovation award
Nominee: 7x

Example

<?php

require_once( 'core'.DIRECTORY_SEPARATOR.'autoload.php' );

use
Core\UserAgent;


if( isset(
$_GET['user_agent'] ) )
   
// Custom User Agent
   
$instance = new UserAgent( $_GET['user_agent'] );

else
   
// System User Agent
   
$instance = new UserAgent();

?>
<!DOCTYPE html>
<html>
    <head>
        <title>User Agent Analayser</title>
        <meta charset="UTF-8"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <link type="text/css" rel="stylesheet" href="css/bootstrap.min.css"/>
        <link type="text/css" rel="stylesheet" href="css/bootstrap-theme.min.css"/>
        <link type="text/css" rel="stylesheet" href="css/style.css"/>

    </head>
    <body>
       
        <div class="container">
            <div class="row">
                <div class="col-md-offset-2 col-md-8">
                    <form method="get">
                        <div class="form-group">
                                <div class="row">
                                    <div class="col-xs-12 col-sm-8">
                                        <input type="text" name="user_agent" class="form-control" value="<?php echo !empty($_GET['user_agent']) ? $_GET['user_agent'] : '' ?>" placeholder="Type User Agent String" required minLength="20" >
                                    </div>
                                    <div class="col-xs-6 col-sm-2">
                                        <button class="btn btn-success btn-block">Analayse</button>
                                    </div>
                                    <div class="col-xs-6 col-sm-2">
                                        <a class="btn btn-warning btn-block" href="<?php echo $_SERVER['PHP_SELF']; ?>">Reset</a>
                                    </div>
                                   
                                </div>
                               
                               
                        </div>
                    </form>

                    <h4 class="text-center text-info">User Agent Information</h4>
                   
                    <div class="table-responsive">
                        <table class="table table-bordered table-striped text-center table-hover">
                           
                            <thead>
                                <tr class="text-primary">
                                    <th class="col-xs-3 text-center">Property</th>
                                    <th class="col-xs-3 text-center">Property Key</th>
                                    <th class="col-xs-1 text-center">Data Type</th>
                                    <th class="col-xs-5 text-center">Value</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td class="text-info"><strong>User Agent String</strong></td>
                                    <td><code>string<code></td>
                                    <td rowspan="8"><code>String<code></td>
                                    <td class="text-left"><small><samp><?php echo $instance->string; ?><samp></small></td>
                                </tr>

                                <tr>
                                    <td class="text-info"><strong>System String</strong></td>
                                    <td><code>systemString<code></td>
                                    <td class="text-left"><small><samp><?php echo $instance->systemString; ?><samp></small></td>
                                </tr>

                                <tr>
                                    <td class="text-info"><strong>Browser Name</strong></td>
                                    <td><code>browserName<code></td>
                                    <td class="text-left"><samp><?php echo $instance->browserName; ?><samp></td>
                                </tr>

                                <tr>
                                    <td class="text-info"><strong>Browser Version</strong></td>
                                    <td><code>browserVersion<code></td>
                                    <td class="text-left"><samp><?php echo $instance->browserVersion; ?><samp></td>
                                </tr>

                                <tr>
                                    <td class="text-info"><strong>Platform</strong></td>
                                    <td><code>osPlatform<code></td>
                                    <td class="text-left"><samp><?php echo $instance->osPlatform; ?><samp></td>
                                </tr>

                                <tr>
                                    <td class="text-info"><strong>OS Version</strong></td>
                                    <td><code>osVersion<code></td>
                                    <td class="text-left"><samp><?php echo $instance->osVersion; ?><samp></td>
                                </tr>

                                <tr>
                                    <td class="text-info"><strong>OS Short Version</strong></td>
                                    <td><code>osShortVersion<code></td>
                                    <td class="text-left"><samp><?php echo $instance->osShortVersion; ?><samp></td>
                                </tr>

                                <tr>
                                    <td class="text-info"><strong>Os Architecture</strong></td>
                                    <td><code>osArch<code></td>
                                    <td class="text-left"><samp><?php echo $instance->osArch ? $instance->osArch : '-'; ?><samp></td>
                                </tr>

                                <tr>
                                    <td class="text-info text-center" rowspan="3"><strong>CPU Brand</strong></td>
                                    <td><code>isIntel<code></td>
                                    <td rowspan="4"><code>Boolean<code></td>
                                    <td class="text-left"><samp><?php echo $instance->isIntel ? 'Yes' : '-'; ?><samp></td>
                                </tr>

                                <tr>
                                    <td><code>isAMD<code></td>
                                    <td class="text-left"><samp><?php echo $instance->isAMD ? 'Yes' : '-'; ?><samp></td>
                                </tr>

                                <tr>
                                    <td><code>isPPC<code></td>
                                    <td class="text-left"><samp><?php echo $instance->isPPC ? 'Yes' : '-'; ?><samp></td>
                                </tr>

                                <tr>
                                    <td class="text-info"><strong>Is Mobile</strong></td>
                                    <td><code>isMobile<code></td>
                                    <td class="text-left"><samp><?php echo $instance->isMobile ? 'Yes' : '-'; ?><samp></td>
                                </tr>

                                <tr>
                                    <td class="text-info"><strong>Mobile Name</strong></td>
                                    <td><code>mobileName<code></td>
                                    <td><code>String<code></td>
                                    <td class="text-left"><samp><?php echo $instance->mobileName ? $instance->mobileName : '-'; ?><samp></td>
                                </tr>

                            </tbody>
                        </table>
                    </div>
                   
                </div>
            </div>
        </div>

        <div class="row">
            <footer id="footer">
           
                <div class="col-sm-6">
                    Developed By Ahmed Saad &copy; 2013-2016<br />
                    <small>a7mad.sa3d.2014@gmail.com</small><br />
                    <cite title="telephone">Tel: +2 01011772100</cite>
                </div>
                <div class="col-sm-6">
               
                    <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International License</a>.
                </div>
            </footer>
        </div>
       

        <!-- Foot Scripts -->
        <script type="text/javascript">

            function setFooterHeight(){
                // sticky Footer
                var footer = document.getElementById( 'footer' );

                var footerHeight = footer.scrollHeight,
                    body = document.getElementsByTagName('body')[0];

                body.style.marginBottom = footerHeight + 'px';
            }

            setFooterHeight();

            window.onresize = function(){

                setFooterHeight();
            }
           
       
        </script>

    </body>
</html>



Details

PHP-UserAgent

Screen Shoot

>UserAgent Class Analayse client user agent string by default, or a given user agent string and gives you very helpfull information about user system and browser.

License

>This Work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. > Link

Copyright

>@author __Ahmed Saad__ <a7mad.sa3d.2014@gmail.com> 2013-2016

Version

> 2.0.0

Updated

> 31 Jul 2016

Features:

  1. Get System and Browser Information about your Visitor as the following: 1. Smart Phones Mobile Detecting. 2. System Archetecture ( 32bit Or 64bit ). 3. CPU Brand Detecting ( `Intel`, `AMD`, `PPC` ). 4. Platform Detecting for Desktop OS and Smart Phone OS. 5. Optimization : Client UserAgent Only Processed Once 6. Read Only Access Properties .

Usage:

> UserAgent Class Uses namespace, and autoload will automatically load class when called.

>> include or requireuser_agent.php* file >> >> <?php >> require_once('core/user_agent.php'); >> use Core\UserAgent; >> $instance = new UserAgent(); >> >> just require or include Suppliedautoload.php* file which will load any class >> >> <?php >> require_once('core/autoload.php'); >> use Core\UserAgent; >> $instance = new UserAgent();

$instance = new UserAgent():

>

// Current Client Systen
$instance = new UserAgent();

>

// Custom UserAgent String
$instance = new UserAgent( 'custom user agent string here' );

$instance->string:

> __String__ useragent string .

$instance->systemString:

> __String__ system string .

$instance->browserName:

> __String__ Browser Name __Google Chrome, Mozilla Firefox, Safari, Opera, Internet Explorer, Android Browser__ .

$instance->browserVersion:

> __String__ Browser Version .

$instance->osPlatform:

> __String__ OS Platform Name .

$instance->osVersion:

> __String__ OS Version .

$instance->osShortVersion:

> __String__ OS Short Version .

$instance->osArch:

> __String__ OS bit Architecture __32 OR 64__ .

$instance->isIntel:

> __Boolean__ Detect if System CPU is Intel .

$instance->isAMD:

> __Boolean__ Detect if System CPU is AMD .

$instance->isPPC:

> __Boolean__ Detect if System CPU is PowerPC .

$instance->isMobile:

> __Boolean__ Detect if client device is Mobile Phone Or Tablet .

$instance->mobileName:

> __String__ Mobile Device Name .


  Files folder image Files  
File Role Description
Files folder imagecore (3 files)
Files folder imagecss (3 files)
Accessible without login Plain text file index.php Example Example script
Accessible without login Plain text file LICENCE Lic. License text
Accessible without login Plain text file README.md Data Auxiliary data

  Files folder image Files  /  core  
File Role Description
  Accessible without login Plain text file autoload.php Aux. Auxiliary script
  Accessible without login Plain text file useragents.txt Data Documentation
  Plain text file user_agent.php Class Class source

  Files folder image Files  /  css  
File Role Description
  Accessible without login Plain text file bootstrap-theme.min.css Data Auxiliary data
  Accessible without login Plain text file bootstrap.min.css Data Auxiliary data
  Accessible without login Plain text file style.css Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:480
This week:1
All time:5,945
This week:99Up
 User Ratings  
 
 All time
Utility:91%StarStarStarStarStar
Consistency:91%StarStarStarStarStar
Documentation:-
Examples:87%StarStarStarStarStar
Tests:-
Videos:-
Overall:63%StarStarStarStar
Rank:789