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: 483 This week: 1All time: 5,928 This week: 44Up
Version License PHP version Categories
php-useragent 1.0.2Custom (specified...5HTTP, PHP 5, Parsers


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: 214021 in Egypt Egypt
Week rank: 52 Up2 in Egypt Egypt Up
Innovation award
Innovation award
Nominee: 7x



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


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

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

<!DOCTYPE html>
        <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"/>

        <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 class="col-xs-6 col-sm-2">
                                        <button class="btn btn-success btn-block">Analayse</button>
                                    <div class="col-xs-6 col-sm-2">
                                        <a class="btn btn-warning btn-block" href="<?php echo $_SERVER['PHP_SELF']; ?>">Reset</a>

                    <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">
                                <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>
                                    <td class="text-info"><strong>User Agent String</strong></td>
                                    <td rowspan="8"><code>String<code></td>
                                    <td class="text-left"><small><samp><?php echo $instance->string; ?><samp></small></td>

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

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

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

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

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

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

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

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

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

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

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

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


        <div class="row">
            <footer id="footer">
                <div class="col-sm-6">
                    Developed By Ahmed Saad &copy; 2013-2016<br />
                    <small></small><br />
                    <cite title="telephone">Tel: +2 01011772100</cite>
                <div class="col-sm-6">
                    <a rel="license" href=""><img alt="Creative Commons License" style="border-width:0" src="" /></a><br />This work is licensed under a <a rel="license" href="">Creative Commons Attribution-ShareAlike 4.0 International License</a>.

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

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

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

       = footerHeight + 'px';


            window.onresize = function(){





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.


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


>@author __Ahmed Saad__ <> 2013-2016


> 2.0.0


> 31 Jul 2016


  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 .


> 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' );


> __String__ useragent string .


> __String__ system string .


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


> __String__ Browser Version .


> __String__ OS Platform Name .


> __String__ OS Version .


> __String__ OS Short Version .


> __String__ OS bit Architecture __32 OR 64__ .


> __Boolean__ Detect if System CPU is Intel .


> __Boolean__ Detect if System CPU is AMD .


> __Boolean__ Detect if System CPU is PowerPC .


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


> __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 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  
This week:1
All time:5,928
This week:44Up
 User Ratings  
 All time