Screen Scraping AWStats
If you need to fetch statistics and information from your AWStats in order to re-use or integrate the data into another web application then you can do this by screen scraping the required information. The following scripts allow you to fetch unique visitor numbers and phrases for which people have come to your site after searching on search engines. The script is primarily for where AWStats is installed on cPanel at the url domain.com:2082/awstats.pl. If your AWStats is installed elsewhere just edit the $url variable. Simply fill in your cPanel username, password and domain name then run the scripts
Unique Visitors
Fetching unique visitor numbers, this code will give you a multi dimensional array, each array key containing an array with 12 values, one for each month of the year. $matches[1] contains the unique visitors for each month of the year. $matches[2] contains the number of visits, $matches[3] the pages loaded, $matches[4] hits and $matches[5] contains bandwidth transferred.
$username = 'username'; $password = 'password'; $url = 'domain.com'; $year = date('Y'); /* replace with 4 digit year */ $url = "http://".$username.":".$password."@".$url.":2082/awstats.pl?month=01&year=".$year."&config=".$url."&lang=en&framename=mainright&output=main"; $buffer = file_get_contents($url); $buffer = strip_tags($buffer,"<tr><td>"); $regex = "{<tr><td>[0-9A-Za-z\s]*</td><td>([0-9]*)</td><td>([0-9]*)</td><td>([0-9]*)</td><td>([0-9]*)</td><td>([0-9A-Z\.\s]*)</td></tr>\n}"; preg_match_all($regex,$buffer,$matches); print_r($matches[1]);
Search Engine Phrases
Fetching search engine phrases, this code will give you an array containing all the search phrases for which users have come to the site for in a given month.
$username = 'username'; $password = 'password'; $url = 'domain.com'; $year = date('Y'); /* replace with 4 digit year */ $month = date('m'); /* replace with 2 digit month */ $url = "http://".$username.":".$password."@".$url.":2082/awstats.pl?month=".$month."&year=".$year."&config=".$url."&lang=en&framename=mainright&output=keyphrases"; $buffer = file_get_contents($url); $regex = "{<tr><td class=\"aws\">([^<]*)</td><td>[^<]*</td><td>[^<]*</td></tr>\n}"; preg_match_all($regex,$buffer,$matches); print_r($matches[1]);



