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.
- 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 = ‘mydomain.com‘;//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
awstats.sourceforge.net. 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’);
NO NEED TO TOUCH ANYTHING BELOW HERE
//retrieves the file, either .pl or .png
global $user, $pass, $domain;
$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 = “awstats.pl?config=$config_domain”;
else //otherwise, all other accesses
$fileQuery = ‘awstats.pl?’.$_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(‘awstats.pl’, 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
//output the 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 .
- Please make sure you replace the changes as per your details given above.
- 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: http://www.yourwebsite.com/stats/
At this point, you should now be able to access AwStats with this URL: http://www.yourwebsite.com/stats/
But we’re not over yet. We don’t want everybody to access our statistics!
- Log in cPanel and click on the Password Protect Directories icon. Browse to your public_html directory and select the stats folder.
- 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.
- You should get a confirmation message saying that the directory is now protected. Click the Go Back link.
- In the Create User section, enter the username and password you want to use to access AwStats and click on Add/modify authorized user.
- Now try to access AwStats (http://www.yourwebsite.com/stats/) 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.: http://stats.yourwebsite.com).
Ok great we can now access AwStats outside cPanel. But we can make things even easier. How about accessing your stats at http://www.yourwebsite.com/stats and not having to specify the configuration file?
Now try to open http://www.yourwebsite.com/stats 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!