I'm using forecast.io to provide weather data on my website. I get charged for every API call from my website.
The problem is when Google crawls my site, it generates an API call and I get charged for it. I'm trying to stop Googlebot from triggering the API call. This is what I've tried and it doesn't seem to prevent the API calls. I'm still receiving 3000 calls a day, from all the crawling activity.
<?php
if(strstr(strtolower($_SERVER['HTTP_USER_AGENT']), "googlebot"))
{
echo "<h1>Today's weather</h1>";
}
else{
include("assets/php/forecast.php");
$api_key = '123123';
$latitude = $lat;
$longitude = $lon;
if ( $latitude !='NULL' && $longitude !='NULL'){
$forecast = new ForecastIO($api_key);
/*
* GET CURRENT CONDITIONS
*/
$condition = $forecast->getCurrentConditions($latitude, $longitude);
}
else {
$latitude = "-33.859972";
$longitude = "151.209444";
$forecast = new ForecastIO($api_key);
$condition = $forecast->getCurrentConditions($latitude, $longitude);
}
$temp = $condition->getTemperature();
$temp = $temp + 2;
$summ = $condition->getSummary();
$icon = $condition->getIcon();
$icon2 = $condition->getIcon();
$icon = str_replace('-', '_', $icon);
$icon2 = str_replace('-', ' ', $icon2);
$icon = strtoupper($icon);
$icon2 = ucfirst($icon2);
}
?>
Currently <?php
if(strstr(strtolower($_SERVER['HTTP_USER_AGENT']), "googlebot"))
{
$min=10;
$max=40;
echo rand($min,$max);
}
else
{
echo $temp;
}
?>°C
Today:
<?php
if(strstr(strtolower($_SERVER['HTTP_USER_AGENT']), "googlebot"))
{
echo "Pleasant";
}
else
{
echo $summ;
} ?> day.
Present weather: <?php
if(strstr(strtolower($_SERVER['HTTP_USER_AGENT']), "googlebot"))
{
echo "Pleasant";
}
else
{
echo $icon2;
} ?></font>
<canvas id="icon1" width="40" height="40"></canvas>
<script>
var skycons = new Skycons({"color": "black"});
skycons.add("icon1", Skycons.<?php
if(strstr(strtolower($_SERVER['HTTP_USER_AGENT']), "googlebot"))
{
echo "PARTLY_CLOUDY_NIGHT";
}
else
{
echo $icon;
} ?>);
skycons.play();
</script>