Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

There are over 10 stats packages installed in my server (AWStat, Webalizer, etc) and cPanel has an interface to show them in terms of visitors, bandwidth, popular pages, etc.

It is possible to access those stats through PHP?

Possible applications include getting a list of most popular content, reporting on visitors and taking actions depending on bandwidth, etc. I know that many of these features can be implemented by creating my own stats counting system but since that information is already somewhere, it could be awesome not to have to write more code to collect it.

share|improve this question
    
This is half an answer. All those packages are using the same source for their data - the raw access logs - which you can get at using cPanel too. So if you search for "php access log analyzer" or variations (such as apache log) then that will give some possibilities. –  paulmorriss May 18 '11 at 8:04
add comment

1 Answer 1

up vote 2 down vote accepted

There's no official cPanel API to access detailed stats data. There are, however, a few scripted workarounds:

  1. There's a reference to scripting cPanel access to scrape AWStats output with PHP here.

  2. There are also GPL-licenced projects to access Apache/AWStats log data with PHP here (via log exporter) and here (via access panel). The log exporter looks like it might be the more useful of the two in your case.

  3. There's some PHP code to display Webalizer stats without logging in to cPanel here and a method to make Webalizer stats public with htaccess here. (You'd then have to scrape data from the Webalizer html table, which is less than ideal.)

These solutions all feel a little hacked together, though. If you're building a custom control panel to display visitor stats, I'd suggest using Google Analytics with the official Analytics API, which provides read-only access to traffic data.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.