How do I display Awstats publicly in Linux Shared Hosting?

There is no direct way of displaying statistics of your domain on your website, you can use the below script 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 ANYTHING BELOW HERE */

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

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

//probably first time to access 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 appropriate header
else {
header("Content-type: image/png");
}

//output the file
echo $file;
?>

Note: This article is for the 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.

  • 650 Users Found This Useful

Was this answer helpful?

Related Articles

Can I upgrade my shared hosting plan to VPS hosting?

Shared hosting plan cannot be upgraded to VPS hosting directly. You can purchase a separate VPS...

What is the procedure to transfer my web hosting from other web hosting provider to AccuWebHosting.com?

Following article will assist you to transfer your websites to AccuWebHosting server. According...

What is the path of home directory in Windows and Linux Shared Hosting plans?

For Linux users, the path of home directory is /home/username/public_html.For Windows users, the...

Parse ASP pages as normal Text/HTML in cPanel server using MIME type

Problem statement One of our customers had some old .ASP file names on his website. The web...

How Do I send .eml File in Emails?

If you are facing an error like "not allowed extension file" while you send .eml file in emails,...