How To Access AwStats Outside cPanel

Date: December 30th, 2011 | Category: Cpanel, General FAQ

AwStats is my favorite web statistics tool. For cPanel users, there’s no installation needed, AwStats is already installed.
But there are times when you want some people to access their website’s statistics but you don’t necessarily want to give them access to cPanel.
This tutorial will show you how you can make AwStats accessible outside cPanel.

  1. Please open a notepad and paste the code given below :

============== Please copy Below ============not this line

Proxy for viewing Awstats outside of cpanel. I assume no liability.


$user = ‘username‘;//your cpanel username
$pass = ‘password‘;//your cpanel password
$domain = ‘‘;//do not include ‘http://’ or ‘www.’

$config_domain = ”;

If you don’t know what you’re doing, set $dynamic_images equal
to TRUE, and don’t worry about the $image_directory variable.
– Normally, this script will load images by proxy, i.e. awstats.php
is called for each <img> tag and will send the correct
image to the browser. This is not the way the web is designed
to work. So, if you wish to improve performance and lower
bandwidth, you can:
1. Set $dynamic_images to FALSE
2. Create an image directory in your webroot
3. Copy all of awstats image sub-directories to this new directory
4. Point the $image_directory variable to your new directory
You will get all the benefits of cached, static images.
In order to get the Awstats images and their directories, you will
probably need to download an awstats distribution from The final layout will probably look like this:


Under each of those sub-directories will be dozens of .png files.

$dynamic_images = true;
$image_directory = ‘./awstats_images/’;

//lame attempt to combat referrer spam
$spam_words = array(‘mortgage’, ‘sex’, ‘porn’, ‘cock’, ‘slut’, ‘facial’, ‘loving’, ‘gay’, ‘.ro’);


//retrieves the file, either .pl or .png
function get_file($fileQuery)
global $user, $pass, $domain;
return file_get_contents(“http://$user:$pass@$domain:2082/”.$fileQuery);

$requesting_image = (strpos($_SERVER[‘QUERY_STRING’],’.png’)===false)?false:true;

if($requesting_image) //it’s a .png file…
if(!$dynamic_images && !is_dir($image_directory))
$fileQuery = $_SERVER[‘QUERY_STRING’];
elseif(empty($_SERVER[‘QUERY_STRING’]))//probably first time to access page…
$config_domain = $domain;
$fileQuery = “$config_domain”;
else //otherwise, all other accesses
$fileQuery = ‘’.$_SERVER[‘QUERY_STRING’];

$file = get_file($fileQuery);

//check again to see if it was a .png file
//if it’s not, replace the links
$file = str_replace(‘’, basename($_SERVER[‘PHP_SELF’]), $file);

$imgsrc_search = ‘=”/images’;
$imgsrc_replace = ‘=”‘.basename($_SERVER[‘PHP_SELF’]).’?images’;
$imgsrc_search = ‘src=”/images/awstats/’;
$imgsrc_replace = ‘src=”‘.$image_directory;

$file = str_replace($imgsrc_search, $imgsrc_replace, $file);
$file = str_replace($spam_words, ‘SPAM’, $file);
else //if it is a png, output appropriate header
header(“Content-type: image/png”);

//output the file
echo $file;
============== Please copy above============not this line

Now save it with a name file index.php or you can copy code only and paste in index.php from HERE .

  1. Please make sure you replace the changes as per your details given above.
  2. Using an FTP client or cpanel file manager , create a directory at the root of your website (ie.: /public_html) and name it “stats” (or whatever you’d like to call it). At this point your directory should be accessible like this:

At this point, you should now be able to access AwStats with this URL:
But we’re not over yet. We don’t want everybody to access our statistics!

  1. Log in cPanel and click on the Password Protect Directories icon. Browse to your public_html directory and select the stats folder.
  2. Check the Password protect this directory checkbox and enter a name for the protected directory (you can enter whatever you want, it doesn’t matter). Click on the Save button when done.
  3. You should get a confirmation message saying that the directory is now protected. Click the Go Back link.
  4. In the Create User section, enter the username and password you want to use to access AwStats and click on Add/modify authorized user.
  5. Now try to access AwStats ( again to make sure it is protected.

Note for WordPress users: password-protecting a subdirectory will not work because of the redirections instructions in the .htaccess file at the root of your website. While it’s not impossible to make it work, it’s easier to create a subdomain for awstats (ie.:
Ok great we can now access AwStats outside cPanel. But we can make things even easier. How about accessing your stats at and not having to specify the configuration file?

Now try to open with your web browser. You should now be prompted for a username and password. You will then be redirected automatically to your statistics page!
That’s it, you’re done!

Article published on Sibername Help Center -

Print this article!