How Do I Display AWStats Publicly in Shared Web Hosting? Print

  • 650

There is no direct way of displaying statistics of your domain on your website, but you can use the script given below to accomplish this – 

<?php
$user = 'username'; //your cPanel username
$pass = 'password'; //your cPanel password
$domain = 'website.com'; //do not include 'http://' or 'www.'

/* NO NEED TO TOUCH/ CHANGE ANYTHING BELOW */

//retrieves the file, either .pl or .png
function getFile($fileQuery){
global $user, $pass, $domain;
return file_get_contents("http://$user:[email protected]$domain:2082/".$fileQuery,'r');
}

//it's a .png file...

if(strpos($_SERVER['QUERY_STRING'],'.png')!==false) {
$fileQuery = $_SERVER['QUERY_STRING'];
}

//probably the first time to access the page

elseif(empty($_SERVER['QUERY_STRING'])){
$fileQuery = "awstats.pl?config=$domain";
}

//otherwise, all other accesses

else {
$fileQuery = 'awstats.pl?'.$_SERVER['QUERY_STRING'];
}

//now get the file

$file = getFile($fileQuery);

//check again to see if it was a .png file
//if it's not, replace the links

if(strpos($_SERVER['QUERY_STRING'],'.png')===false) {
$file = str_replace('awstats.pl', basename($_SERVER['PHP_SELF']), $file);
$file = str_replace('="/images','="'.basename($_SERVER['PHP_SELF']).'?images',$file);
}

//if it is a png, output the appropriate header

else {
header("Content-type: image/png");
}

//output the file

echo $file;
?>

Note
This article is for cPanel users only. 

This script requires that you save your cPanel username and password in the php file, which is a security risk. Thus, users are requested to use this script at their own risk. 

AccuWebHosting.com has not written this script; thus, it will not provide any support for any issues arising out of the usage of this script.
 
 

Was this answer helpful?

« Back

chat