Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php include_once('functions.php');?> <link rel="stylesheet" href="https://ma..

Decoded Output download

<?  &lt;?php include_once('functions.php');?&gt; 
 
&lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"&gt; 
&lt;link rel="stylesheet" href="css/style.css"&gt; 
&lt;script type="text/javascript" src="https://code.jquery.com/jquery-1.10.1.min.js"&gt;&lt;/script&gt; 
 
&lt;style type="text/css"&gt; 
  .count{ 
    font-size: 50px; 
  } 
  .open-link:hover{ 
    background: #ddd; 
    cursor: pointer; 
  } 
 	body{ 
 		background: aliceblue; 
 	} 
 	.header{ 
 		background: #2285ef; 
 		height: 50px; 
 		display: flex; 
 		align-items: center; 
 		justify-content: center; 
 		color: #fff; 
 		font-size: 18px; 
 	} 
  .page-content{ 
    margin-top: 20px; 
  } 
  .site-name{ 
    cursor: pointer; 
    font-size: 25px; 
  } 
   
  .site-list{ 
    display: none; 
    position: absolute; 
    padding: 30px; 
    background: #ddd; 
    top: 50px; 
    z-index: 100; 
    background: #000; 
    padding: 0px; 
  } 
  table { 
    background: #fff; 
    -webkit-box-shadow: 0px 0px 5px -1px rgba(158,155,158,1); 
    -moz-box-shadow: 0px 0px 5px -1px rgba(158,155,158,1); 
    box-shadow: 0px 0px 5px -1px rgba(158,155,158,1); 
    padding-bottom: 15px; 
  } 
  h1,p{ 
  		text-align: center; 
  } 
  .progress { 
    display: flex; 
  } 
  .progress-cotent{ 
    position: absolute; 
      text-align: center; 
      width: inherit; 
      padding-top: 5px; 
  } 
  .count{ 
    font-size: 86px; 
  } 
  .progress-bar-success, .label-success:before {background-color: #50b432;} 
  .progress-bar-warning, .label-warning:before {background-color: #ed561b;} 
  .progress-bar-danger, .label-danger:before {background-color: #058dc7;} 
  .label-success, .label-warning, .label-danger{background: transparent;color: #444;display: inline-block;font-size: 1em;line-height: 1.1em;font-weight: bold;font-family: arial;} 
  .progress-label .label:before{content:'';width:10px; height:10px;float:left; margin-right:3px;} 
  .progress-bar-danger span, .label-success span + span, .label-warning span + span{} 
  .progress-label{text-transform:uppercase;font-size:0.8em; font-weight:bold;margin:5px 0 8px} 
  .table{border-radius:5px 5px 0 0;box-shadow:inherit; -webkit-box-shadow:inherit; border-top:2px solid #666} 
  .table  th{background:#fff;padding:10px 8px; height:auto;font-size:0.95em;} 
  .table tr:nth-child(odd) td:nth-child(even) { background: rgba(0,0,0,0.03);text-align:center;} 
  .table tr:nth-child(even) td { background: rgba(0,0,0,0.02)} 
  .table tr:nth-child(even) td:nth-child(even) { background: rgba(0,0,0,0.06);text-align:center;} 
  .table&gt;tbody&gt;tr&gt;td{padding:7px 8px;color:#444; font-size:0.95em;} 
  .table td{width:90%} 
  .table td:nth-child(even){width:10%;} 
  .col-md-3 .table td{width:64%} 
  .col-md-3 .table td:nth-child(even){width:36%;} 
  @media (max-width:768px){ 
    .col-md-9, .col-md-3{padding:0} 
  } 
  @media (max-width: 991px) { 
      .col-md-3.pull-right { 
          float: none !important; 
      } 
  } 
&lt;/style&gt; 
 
 
 
&lt;div class="container page-content"&gt; 
  &lt;div class="row"&gt; 
    &lt;div class="col-md-8"&gt; 
      &lt;table class="table table-bordered" id="result-pages"&gt; 
        &lt;thead&gt; 
          &lt;tr&gt; 
            &lt;th width="40%"&gt;Top Active Pages&lt;/th&gt; 
            &lt;th&gt;Users&lt;/th&gt; 
          &lt;/tr&gt; 
        &lt;/thead&gt; 
        &lt;tbody&gt; 
        &lt;/tbody&gt; 
      &lt;/table&gt; 
    &lt;/div&gt; 
    &lt;div class="col-md-4"&gt; 
      &lt;table class="table table-bordered"&gt; 
            	&lt;tbody&gt; 
            		&lt;tr&gt; 
              			&lt;th&gt;Right Now&lt;/th&gt; 
        			&lt;/tr&gt; 
            		&lt;tr&gt; 
              			&lt;td&gt; 
                			&lt;h1&gt; 
                                &lt;div class="count" id="active-users"&gt; 
                                &lt;/div&gt; 
                			&lt;/h1&gt; 
                			&lt;p&gt;Active Users on Site&lt;/p&gt; 
                			&lt;br&gt; 
                			&lt;div id="devices"&gt; 
           					&lt;/div&gt; 
        				&lt;/td&gt; 
        			&lt;/tr&gt; 
      			&lt;/tbody&gt; 
      		&lt;/table&gt; 
      		 
      		&lt;table class="table table-bordered" id="result-sources"&gt; 
      			&lt;thead&gt; 
      				&lt;tr&gt; 
      					&lt;th&gt;Source&lt;/th&gt; 
      					&lt;th&gt;Users&lt;/th&gt; 
      				&lt;/tr&gt; 
      			&lt;/thead&gt; 
      			&lt;tbody&gt; 
      			&lt;/tbody&gt; 
      		&lt;/table&gt; 
      		 
      		&lt;table class="table table-bordered" id="countries-sources"&gt; 
      			&lt;thead&gt; 
      				&lt;tr&gt; 
      					&lt;th&gt;Country&lt;/th&gt; 
      					&lt;th&gt;Users&lt;/th&gt; 
      				&lt;/tr&gt; 
      			&lt;/thead&gt; 
      			&lt;tbody&gt; 
 
      			&lt;/tbody&gt; 
      		&lt;/table&gt; 
 
      		&lt;table class="table table-bordered" id="browser-sources"&gt; 
      			&lt;thead&gt; 
      				&lt;tr&gt; 
      					&lt;th&gt;Browser&lt;/th&gt; 
      					&lt;th&gt;Users&lt;/th&gt; 
      				&lt;/tr&gt; 
      			&lt;/thead&gt; 
      			&lt;tbody&gt; 
      			&lt;/tbody&gt; 
      		&lt;/table&gt; 
      		&lt;table class="table table-bordered" id="os-sources"&gt; 
      			&lt;thead&gt; 
      				&lt;tr&gt; 
      					&lt;th&gt;OS&lt;/th&gt; 
      					&lt;th&gt;Users&lt;/th&gt; 
      				&lt;/tr&gt; 
      			&lt;/thead&gt; 
      			&lt;tbody&gt; 
      			&lt;/tbody&gt; 
      		&lt;/table&gt; 
      		 
    &lt;/div&gt; 
  &lt;/div&gt; 
&lt;/div&gt; 
 
&lt;script type="text/javascript"&gt; 
  setInterval(function(){ 
    call(); 
  },5000); 
 
  function call(){ 
    get('pages'); 
    get('users'); 
    get('devices'); 
    get('sources'); 
    get('countries'); 
    get('browser'); 
    get('os'); 
  } 
  call(); 
 
  function get(action){ 
    var view = '&lt;?php echo VIEW;?&gt;'; 
    $.ajax({ 
      url:"ajax.php?action="+action+'&amp;view='+view, 
      type:'get', 
      success:function(res){ 
        if(action=='pages'){ 
          $("#result-pages tbody").html(res); 
        } 
        else if(action=='users'){ 
          $("#active-users").html(res); 
        } 
        else if(action=='devices'){ 
          $("#devices").html(res); 
        } 
        else if(action=='sources'){ 
          $("#result-sources tbody").html(res); 
        } 
        else if(action=='countries'){ 
          $("#countries-sources tbody").html(res); 
        } 
        else if(action=='browser'){ 
          $("#browser-sources tbody").html(res); 
        } 
        else if(action=='os'){ 
          $("#os-sources tbody").html(res); 
        } 
      } 
    }); 
  } 
 
  $(document).on('click','.open-link',function(){ 
    link = $(this).attr('data-link'); 
    link = '&lt;?php echo DOMAIN;?&gt;'+link; 
    window.open(link, '_blank'); 
  }); 
&lt;/script&gt; 
</pre> 
<h2>Step 6 : Create functions.php file</h2> 
<p>functions.php</p> 
<pre class="EnlighterJSRAW" data-enlighter-language="null">&lt;?php 
 
define('VIEW','194594240'); 
define('SERVICE_ACCOUNT','analytics-325704-1b0b324a12d4.json'); 
define('DOMAIN','https://reeteshghimire.com.np'); 
 
 
function getActivePages($analytics){ 
  $optParams = array( 
    'dimensions' =&gt; 'rt:pageTitle,rt:pagePath', 
    'sort' =&gt; '-rt:activeVisitors', 
    'max-results' =&gt; '16' 
  ); 
  $result = $analytics 
        -&gt;data_realtime 
        -&gt;get('ga:'.VIEW, 'rt:activeVisitors',$optParams); 
 
  $table = ''; 
  if($result){ 
    $rows = $result-&gt;getRows(); 
    if($rows){ 
      foreach($rows as $row){ 
        $table .= '&lt;tr class="open-link" data-link="'.$row[1].'"&gt;'; 
        $table .= '&lt;td&gt;'.htmlspecialchars($row[0],ENT_NOQUOTES).'&lt;/td&gt;'; 
        $table .= '&lt;td&gt;'.htmlspecialchars($row[2],ENT_NOQUOTES).'&lt;/td&gt;'; 
        $table .= '&lt;/tr&gt;'; 
      } 
    }else{ 
      $table .= '&lt;tr&gt;&lt;td colspan="2"&gt;&lt;small&gt;There is no data to view&lt;/small&gt;&lt;/td&gt;&lt;/tr&gt;'; 
    } 
    return $table; 
  }else{ 
    return '&lt;tr&gt;&lt;td colspan="2"&gt;&lt;small&gt;There is no data to view&lt;/small&gt;&lt;/td&gt;&lt;/tr&gt;'; 
  } 
} 
 
function getActiveUsers($analytics){ 
  $active_users = $analytics 
          -&gt;data_realtime 
          -&gt;get('ga:'.VIEW, 'rt:activeVisitors'); 
  $active_users = (isset($active_users-&gt;rows[0][0]))?$active_users-&gt;rows[0][0]:0; 
  return $active_users; 
} 
 
function getDevices($analytics){ 
  $optParams = array( 
    'dimensions' =&gt; 'rt:deviceCategory', 
    'sort' =&gt; '-rt:activeVisitors' 
  ); 
 
  $devices = $analytics 
        -&gt;data_realtime 
        -&gt;get('ga:'.VIEW, 'rt:activeVisitors',$optParams); 
  $html = ''; 
  if($devices-&gt;rows){ 
    $total = 0; 
    $class = array('warning','success','danger'); 
    foreach($devices-&gt;rows as $row){ 
      $total += $row[1]; 
    } 
    $loop = 0; 
    $html .= '&lt;div class="progress_label"&gt;'; 
    foreach($devices-&gt;rows as $row){ 
      $percent = round(($row[1]/$total)*100); 
      $html .= '&lt;div class="label label-'.$class[$loop].'"&gt;'; 
      $html .= '&lt;span&gt;'.$row[0].'&lt;/span&gt;'; 
      $html .= '&lt;span&gt;'.$row[1].'&lt;/span&gt;'; 
      $html .= '&lt;/div&gt;'; 
      $loop++; 
    } 
    $html .= '&lt;/div&gt;'; 
    $loop = 0; 
    $html .= '&lt;div class="progress" style="width:100%!important"&gt;'; 
    foreach($devices-&gt;rows as $row){ 
      $html .= '&lt;div class="progress-bar progress-bar-'.$class[$loop].'" style="width:'.$percent.'%"&gt;&lt;/div&gt;'; 
      $loop++; 
    } 
    $html .= '&lt;/div&gt;'; 
  } 
  return $html; 
} 
 
 
function getFormattedData($result){ 
  $table = ''; 
  if($result){ 
    $rows = $result-&gt;getRows(); 
    if($rows){ 
      foreach($rows as $row){ 
        $table .= '&lt;tr&gt;'; 
        foreach($row as $cell){ 
          $table .= '&lt;td&gt;'.htmlspecialchars($cell,ENT_NOQUOTES).'&lt;/td&gt;'; 
        } 
        $table .= '&lt;/tr&gt;'; 
      } 
    }else{ 
      $table .= '&lt;tr&gt;&lt;td colspan="2"&gt;&lt;small&gt;There is no data to view&lt;/small&gt;&lt;/td&gt;&lt;/tr&gt;'; 
    } 
    return $table; 
  }else{ 
    return '&lt;tr&gt;&lt;td colspan="2"&gt;&lt;small&gt;There is no data to view&lt;/small&gt;&lt;/td&gt;&lt;/tr&gt;'; 
  } 
} 
 
function getTrafficSources($analytics){ 
  $optParams = array( 
    'dimensions' =&gt; 'rt:source', 
    'sort' =&gt; '-rt:activeVisitors', 
    'max-results' =&gt; 5 
  ); 
 
  $result = $analytics 
        -&gt;data_realtime 
        -&gt;get('ga:'.VIEW,'rt:activeVisitors',$optParams); 
  return getFormattedData($result); 
} 
 
function getCountries($analytics){ 
  $optParams = array( 
    'dimensions' =&gt; 'ga:country', 
    'sort' =&gt; '-rt:activeVisitors', 
    'max-results' =&gt; 10 
  ); 
 
  $result = $analytics 
        -&gt;data_realtime 
        -&gt;get('ga:'.VIEW,'rt:activeVisitors',$optParams); 
  return getFormattedData($result,'Country','Users'); 
} 
 
 
function getOS($analytics){ 
  $optParams = array( 
    'dimensions' =&gt; 'ga:operatingSystem', 
    'sort' =&gt; '-rt:activeVisitors', 
    'max-results' =&gt; 10 
  ); 
 
  $result = $analytics 
        -&gt;data_realtime 
        -&gt;get('ga:'.VIEW,'rt:activeVisitors',$optParams); 
  return getFormattedData($result,'OS','Users'); 
} 
 
 
function getBrowser($analytics){ 
  $optParams = array( 
    'dimensions' =&gt; 'ga:browser', 
    'sort' =&gt; '-rt:activeVisitors', 
    'max-results' =&gt; 10 
  ); 
 
  $result = $analytics 
        -&gt;data_realtime 
        -&gt;get('ga:'.VIEW,'rt:activeVisitors',$optParams); 
  return getFormattedData($result,'Browser','Users'); 
} ?>

Did this file decode correctly?

Original Code

&lt;?php include_once('functions.php');?&gt;

&lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"&gt;
&lt;link rel="stylesheet" href="css/style.css"&gt;
&lt;script type="text/javascript" src="https://code.jquery.com/jquery-1.10.1.min.js"&gt;&lt;/script&gt;

&lt;style type="text/css"&gt;
  .count{
    font-size: 50px;
  }
  .open-link:hover{
    background: #ddd;
    cursor: pointer;
  }
 	body{
 		background: aliceblue;
 	}
 	.header{
 		background: #2285ef;
 		height: 50px;
 		display: flex;
 		align-items: center;
 		justify-content: center;
 		color: #fff;
 		font-size: 18px;
 	}
  .page-content{
    margin-top: 20px;
  }
  .site-name{
    cursor: pointer;
    font-size: 25px;
  }
  
  .site-list{
    display: none;
    position: absolute;
    padding: 30px;
    background: #ddd;
    top: 50px;
    z-index: 100;
    background: #000;
    padding: 0px;
  }
  table {
    background: #fff;
    -webkit-box-shadow: 0px 0px 5px -1px rgba(158,155,158,1);
    -moz-box-shadow: 0px 0px 5px -1px rgba(158,155,158,1);
    box-shadow: 0px 0px 5px -1px rgba(158,155,158,1);
    padding-bottom: 15px;
  }
  h1,p{
  		text-align: center;
  }
  .progress {
    display: flex;
  }
  .progress-cotent{
    position: absolute;
      text-align: center;
      width: inherit;
      padding-top: 5px;
  }
  .count{
    font-size: 86px;
  }
  .progress-bar-success, .label-success:before {background-color: #50b432;}
  .progress-bar-warning, .label-warning:before {background-color: #ed561b;}
  .progress-bar-danger, .label-danger:before {background-color: #058dc7;}
  .label-success, .label-warning, .label-danger{background: transparent;color: #444;display: inline-block;font-size: 1em;line-height: 1.1em;font-weight: bold;font-family: arial;}
  .progress-label .label:before{content:'';width:10px; height:10px;float:left; margin-right:3px;}
  .progress-bar-danger span, .label-success span + span, .label-warning span + span{}
  .progress-label{text-transform:uppercase;font-size:0.8em; font-weight:bold;margin:5px 0 8px}
  .table{border-radius:5px 5px 0 0;box-shadow:inherit; -webkit-box-shadow:inherit; border-top:2px solid #666}
  .table  th{background:#fff;padding:10px 8px; height:auto;font-size:0.95em;}
  .table tr:nth-child(odd) td:nth-child(even) { background: rgba(0,0,0,0.03);text-align:center;}
  .table tr:nth-child(even) td { background: rgba(0,0,0,0.02)}
  .table tr:nth-child(even) td:nth-child(even) { background: rgba(0,0,0,0.06);text-align:center;}
  .table&gt;tbody&gt;tr&gt;td{padding:7px 8px;color:#444; font-size:0.95em;}
  .table td{width:90%}
  .table td:nth-child(even){width:10%;}
  .col-md-3 .table td{width:64%}
  .col-md-3 .table td:nth-child(even){width:36%;}
  @media (max-width:768px){
    .col-md-9, .col-md-3{padding:0}
  }
  @media (max-width: 991px) {
      .col-md-3.pull-right {
          float: none !important;
      }
  }
&lt;/style&gt;



&lt;div class="container page-content"&gt;
  &lt;div class="row"&gt;
    &lt;div class="col-md-8"&gt;
      &lt;table class="table table-bordered" id="result-pages"&gt;
        &lt;thead&gt;
          &lt;tr&gt;
            &lt;th width="40%"&gt;Top Active Pages&lt;/th&gt;
            &lt;th&gt;Users&lt;/th&gt;
          &lt;/tr&gt;
        &lt;/thead&gt;
        &lt;tbody&gt;
        &lt;/tbody&gt;
      &lt;/table&gt;
    &lt;/div&gt;
    &lt;div class="col-md-4"&gt;
      &lt;table class="table table-bordered"&gt;
            	&lt;tbody&gt;
            		&lt;tr&gt;
              			&lt;th&gt;Right Now&lt;/th&gt;
        			&lt;/tr&gt;
            		&lt;tr&gt;
              			&lt;td&gt;
                			&lt;h1&gt;
                                &lt;div class="count" id="active-users"&gt;
                                &lt;/div&gt;
                			&lt;/h1&gt;
                			&lt;p&gt;Active Users on Site&lt;/p&gt;
                			&lt;br&gt;
                			&lt;div id="devices"&gt;
           					&lt;/div&gt;
        				&lt;/td&gt;
        			&lt;/tr&gt;
      			&lt;/tbody&gt;
      		&lt;/table&gt;
      		
      		&lt;table class="table table-bordered" id="result-sources"&gt;
      			&lt;thead&gt;
      				&lt;tr&gt;
      					&lt;th&gt;Source&lt;/th&gt;
      					&lt;th&gt;Users&lt;/th&gt;
      				&lt;/tr&gt;
      			&lt;/thead&gt;
      			&lt;tbody&gt;
      			&lt;/tbody&gt;
      		&lt;/table&gt;
      		
      		&lt;table class="table table-bordered" id="countries-sources"&gt;
      			&lt;thead&gt;
      				&lt;tr&gt;
      					&lt;th&gt;Country&lt;/th&gt;
      					&lt;th&gt;Users&lt;/th&gt;
      				&lt;/tr&gt;
      			&lt;/thead&gt;
      			&lt;tbody&gt;

      			&lt;/tbody&gt;
      		&lt;/table&gt;

      		&lt;table class="table table-bordered" id="browser-sources"&gt;
      			&lt;thead&gt;
      				&lt;tr&gt;
      					&lt;th&gt;Browser&lt;/th&gt;
      					&lt;th&gt;Users&lt;/th&gt;
      				&lt;/tr&gt;
      			&lt;/thead&gt;
      			&lt;tbody&gt;
      			&lt;/tbody&gt;
      		&lt;/table&gt;
      		&lt;table class="table table-bordered" id="os-sources"&gt;
      			&lt;thead&gt;
      				&lt;tr&gt;
      					&lt;th&gt;OS&lt;/th&gt;
      					&lt;th&gt;Users&lt;/th&gt;
      				&lt;/tr&gt;
      			&lt;/thead&gt;
      			&lt;tbody&gt;
      			&lt;/tbody&gt;
      		&lt;/table&gt;
      		
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;script type="text/javascript"&gt;
  setInterval(function(){
    call();
  },5000);

  function call(){
    get('pages');
    get('users');
    get('devices');
    get('sources');
    get('countries');
    get('browser');
    get('os');
  }
  call();

  function get(action){
    var view = '&lt;?php echo VIEW;?&gt;';
    $.ajax({
      url:"ajax.php?action="+action+'&amp;view='+view,
      type:'get',
      success:function(res){
        if(action=='pages'){
          $("#result-pages tbody").html(res);
        }
        else if(action=='users'){
          $("#active-users").html(res);
        }
        else if(action=='devices'){
          $("#devices").html(res);
        }
        else if(action=='sources'){
          $("#result-sources tbody").html(res);
        }
        else if(action=='countries'){
          $("#countries-sources tbody").html(res);
        }
        else if(action=='browser'){
          $("#browser-sources tbody").html(res);
        }
        else if(action=='os'){
          $("#os-sources tbody").html(res);
        }
      }
    });
  }

  $(document).on('click','.open-link',function(){
    link = $(this).attr('data-link');
    link = '&lt;?php echo DOMAIN;?&gt;'+link;
    window.open(link, '_blank');
  });
&lt;/script&gt;
</pre>
<h2>Step 6 : Create functions.php file</h2>
<p>functions.php</p>
<pre class="EnlighterJSRAW" data-enlighter-language="null">&lt;?php

define('VIEW','194594240');
define('SERVICE_ACCOUNT','analytics-325704-1b0b324a12d4.json');
define('DOMAIN','https://reeteshghimire.com.np');


function getActivePages($analytics){
  $optParams = array(
    'dimensions' =&gt; 'rt:pageTitle,rt:pagePath',
    'sort' =&gt; '-rt:activeVisitors',
    'max-results' =&gt; '16'
  );
  $result = $analytics
        -&gt;data_realtime
        -&gt;get('ga:'.VIEW, 'rt:activeVisitors',$optParams);

  $table = '';
  if($result){
    $rows = $result-&gt;getRows();
    if($rows){
      foreach($rows as $row){
        $table .= '&lt;tr class="open-link" data-link="'.$row[1].'"&gt;';
        $table .= '&lt;td&gt;'.htmlspecialchars($row[0],ENT_NOQUOTES).'&lt;/td&gt;';
        $table .= '&lt;td&gt;'.htmlspecialchars($row[2],ENT_NOQUOTES).'&lt;/td&gt;';
        $table .= '&lt;/tr&gt;';
      }
    }else{
      $table .= '&lt;tr&gt;&lt;td colspan="2"&gt;&lt;small&gt;There is no data to view&lt;/small&gt;&lt;/td&gt;&lt;/tr&gt;';
    }
    return $table;
  }else{
    return '&lt;tr&gt;&lt;td colspan="2"&gt;&lt;small&gt;There is no data to view&lt;/small&gt;&lt;/td&gt;&lt;/tr&gt;';
  }
}

function getActiveUsers($analytics){
  $active_users = $analytics
          -&gt;data_realtime
          -&gt;get('ga:'.VIEW, 'rt:activeVisitors');
  $active_users = (isset($active_users-&gt;rows[0][0]))?$active_users-&gt;rows[0][0]:0;
  return $active_users;
}

function getDevices($analytics){
  $optParams = array(
    'dimensions' =&gt; 'rt:deviceCategory',
    'sort' =&gt; '-rt:activeVisitors'
  );

  $devices = $analytics
        -&gt;data_realtime
        -&gt;get('ga:'.VIEW, 'rt:activeVisitors',$optParams);
  $html = '';
  if($devices-&gt;rows){
    $total = 0;
    $class = array('warning','success','danger');
    foreach($devices-&gt;rows as $row){
      $total += $row[1];
    }
    $loop = 0;
    $html .= '&lt;div class="progress_label"&gt;';
    foreach($devices-&gt;rows as $row){
      $percent = round(($row[1]/$total)*100);
      $html .= '&lt;div class="label label-'.$class[$loop].'"&gt;';
      $html .= '&lt;span&gt;'.$row[0].'&lt;/span&gt;';
      $html .= '&lt;span&gt;'.$row[1].'&lt;/span&gt;';
      $html .= '&lt;/div&gt;';
      $loop++;
    }
    $html .= '&lt;/div&gt;';
    $loop = 0;
    $html .= '&lt;div class="progress" style="width:100%!important"&gt;';
    foreach($devices-&gt;rows as $row){
      $html .= '&lt;div class="progress-bar progress-bar-'.$class[$loop].'" style="width:'.$percent.'%"&gt;&lt;/div&gt;';
      $loop++;
    }
    $html .= '&lt;/div&gt;';
  }
  return $html;
}


function getFormattedData($result){
  $table = '';
  if($result){
    $rows = $result-&gt;getRows();
    if($rows){
      foreach($rows as $row){
        $table .= '&lt;tr&gt;';
        foreach($row as $cell){
          $table .= '&lt;td&gt;'.htmlspecialchars($cell,ENT_NOQUOTES).'&lt;/td&gt;';
        }
        $table .= '&lt;/tr&gt;';
      }
    }else{
      $table .= '&lt;tr&gt;&lt;td colspan="2"&gt;&lt;small&gt;There is no data to view&lt;/small&gt;&lt;/td&gt;&lt;/tr&gt;';
    }
    return $table;
  }else{
    return '&lt;tr&gt;&lt;td colspan="2"&gt;&lt;small&gt;There is no data to view&lt;/small&gt;&lt;/td&gt;&lt;/tr&gt;';
  }
}

function getTrafficSources($analytics){
  $optParams = array(
    'dimensions' =&gt; 'rt:source',
    'sort' =&gt; '-rt:activeVisitors',
    'max-results' =&gt; 5
  );

  $result = $analytics
        -&gt;data_realtime
        -&gt;get('ga:'.VIEW,'rt:activeVisitors',$optParams);
  return getFormattedData($result);
}

function getCountries($analytics){
  $optParams = array(
    'dimensions' =&gt; 'ga:country',
    'sort' =&gt; '-rt:activeVisitors',
    'max-results' =&gt; 10
  );

  $result = $analytics
        -&gt;data_realtime
        -&gt;get('ga:'.VIEW,'rt:activeVisitors',$optParams);
  return getFormattedData($result,'Country','Users');
}


function getOS($analytics){
  $optParams = array(
    'dimensions' =&gt; 'ga:operatingSystem',
    'sort' =&gt; '-rt:activeVisitors',
    'max-results' =&gt; 10
  );

  $result = $analytics
        -&gt;data_realtime
        -&gt;get('ga:'.VIEW,'rt:activeVisitors',$optParams);
  return getFormattedData($result,'OS','Users');
}


function getBrowser($analytics){
  $optParams = array(
    'dimensions' =&gt; 'ga:browser',
    'sort' =&gt; '-rt:activeVisitors',
    'max-results' =&gt; 10
  );

  $result = $analytics
        -&gt;data_realtime
        -&gt;get('ga:'.VIEW,'rt:activeVisitors',$optParams);
  return getFormattedData($result,'Browser','Users');
}

Function Calls

None

Variables

None

Stats

MD5 a5e5ad7c2358502d23a966850520016b
Eval Count 0
Decode Time 38 ms