Ñêðèïò ïðîâåðêè áåêîâ è èíäåêñàöèè ñòðàíè÷åê - øëåò èíôó íà ìûëî
Íàðûë Nike
Creating a Free SEO Tool to Monitor Google Backlinks & Pages Indexed
Here’s a quick rundown on how to use the Google API to create a free seo tool that monitors a site’s backlinks and pages indexed in Google and does not break their terms of service (since it queries using their API). When set with a cron job, the application will monitor the site’s backlinks and pages indexed through out the day and then emails the admin any changes (while logging the data in the database).
Download Google's Developer's Kit
1. Go to http://www.google.com/apis/, download the developer’s kit, and create a google account to obtain a license key. Make sure to reference the API documentation at APIs_Reference.html that is included in the kit (some good stuff there).
Download NuSoap Toolkit
2. Go to http://cvs.sourceforge.net/viewcvs…./lib/nusoap.php and download the NuSoap Toolkit (nusoap.php - Revision 1.76 was used for this example)
Create MySQL Table
3. Run the following SQL to create the table that will hold the data in your database:
Code:
CREATE TABLE `GetGoogleStats` (
`reportId` int(11) NOT NULL auto_increment,
`reportDate` text,
`reportBacklinks` int(11) default NULL,
`reportIndexed` int(11) default NULL,
PRIMARY KEY (`reportId`)
);
Get the Source Code
4. Copy the following code, edit the configuration variables, and save it with the name getgooglestats.php in the same directory that the NuSoap Toolkit (nusoap.php) is saved at.
PHP:
######################
# Set Configuration Variables #
######################
$getHostname = “localhost"; // Hostname
$getUsername = “your_username"; // Username
$getPassword = “your_password"; // Password
$getDatabase = “your_database_name"; // Database Name
$getDomainUrl = “yourdomain.com"; // Site Domain (without the www. prefix)
$adminEmail = “you@yourdomain.com"; // Email address report is sent to
$apiKey = “you_google_api_license_key"; // Google API License Key
######################
# End Configuration Variables #
######################
function GetGoogleStats($getHostname, $getUsername, $getPassword, $getDatabase, $getDomainUrl, $adminEmail, $apiKey){
# Database Connection
$getConnection = mysql_connect($getHostname, $getUsername, $getPassword) or die(mysql_error());
mysql_select_db($getDatabase, $getConnection);
# Set variables
$query_indexed = “site:www.$getDomainUrl";
$query_backlinks = “link:www.$getDomainUrl";
$todaysdate = date("F j, Y, g:i a");
# Use the NuSOAP php library
require_once(’nusoap.php’);
# Set parameters array for pages indexed
$parameters_indexed = array(
‘key’=> $apiKey,
‘q’ => $query_indexed,
’start’ => ‘0′,
‘maxResults’ => ‘5′,
‘filter’ => ‘0′,
‘restrict’ => ‘’,
’safeSearch’ => ‘false’,
‘lr’ => ‘’,
‘ie’ => ‘latin’,
‘oe’ => ‘latin’
);
# Set parameters array for backlinks
$parameters_backlinks = array(
‘key’=> $apiKey,
‘q’ => $query_backlinks,
’start’ => ‘0′,
‘maxResults’ => ‘5′,
‘filter’ => ‘0′,
‘restrict’ => ‘’,
’safeSearch’ => ‘false’,
‘lr’ => ‘’,
‘ie’ => ‘latin’,
‘oe’ => ‘latin’
);
# Create a new SOAP client, feeding it GoogleSearch.wsdl on Google’s site
$soapclient = new soapclient(’http://api.google.com/GoogleSearch.wsdl’, ‘wsdl’);
# query Google
$results_indexed = $soapclient->call(’doGoogleSearch’,$parameters_indexed);
$results_backlinks = $soapclient->call(’doGoogleSearch’,$parameters_backlinks);
# Get Results for Pages Indexed
if ( is_array($results_indexed[’resultElements’]) ) {
$pagesindexed = $results_indexed[’estimatedTotalResultsCount’];
} else {
$pagesindexed = 0;
}
# Get Results for Backlinks
if ( is_array($results_backlinks[’resultElements’]) ) {
$backlinks = $results_backlinks[’estimatedTotalResultsCount’];
} else {
$backlinks = 0;
}
// select google data from last ran report and set to variables
$sqlGoogle = “SELECT * FROM GetGoogleStats ORDER BY reportId DESC LIMIT 1″;
$rsGoogle = mysql_query($sqlGoogle) or die(mysql_error());
$row_rsGoogle = mysql_fetch_assoc($rsGoogle);
$lastDate = $row_rsGoogle[’reportDate’];
$lastPagesIndexed = $row_rsGoogle[’reportIndexed’];
$lastBackLinks = $row_rsGoogle[’reportBacklinks’];
// If any changes
if ($lastPagesIndexed != $pagesindexed || $lastBackLinks != $backlinks){
// Insert Data
$sql = “INSERT INTO GetGoogleStats SET reportDate="$todaysdate", reportBacklinks="$backlinks", reportIndexed="$pagesindexed"";
$rsGoogle = mysql_query($sql) or die(mysql_error());
// Email Results
$headers = “";
$headers .= “MIME-Version: 1.0\r\n";
$headers .= “Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= “From: $getDomainUrl \r\n";
$subject = “Google Report Status for $getDomainUrl - ” . $todaysdate;
$body = “Last Report: ” . $lastDate . “\r\n";
$body .= “Pages Indexed: ” . $lastPagesIndexed . “\r\n";
$body .= “Back Links: ” . $lastBackLinks . “\r\n";
$body .= “Todays Report: ” . $todaysdate . “\r\n";
$body .= “Pages Indexed: ” . $pagesindexed . “\r\n";
$body .= “Back Links: ” . $backlinks . “\r\n";
mail($adminEmail, $subject, $body, $headers);
}
mysql_close($getConnection);
}
# Call Function
GetGoogleStats($getHostname, $getUsername, $getPassword, $getDatabase, $getDomainUrl, $adminEmail, $apiKey);
?>
Upload Files & Set Cron Job
5. Upload the two files (nusoap.php & getgooglestats.php) to the same directory on your server. Next, set a cron job to run getgooglestats.php as often as you wish. Keep in mind that you're limited to 1,000 queries a day with the API license, so I wouldn't recommend setting it to run too often. I usually use the CPANEL Standard Cron Manager that comes with my hosting to do this.
Finish Line
If everything goes right, you should now have it setup so it will automatically check the stats of the site,email you any changes, and log the data into the database. I’ll leave it to you to build any reports with the data.
If you are having problems, feel free to contact me here.
Good luck!
Greg
http://www.jsmcorp.com/web-marketing-article/tool-to-monitor-site-in-google.html
MORE...