我使用forecast.io在我的网站上提供天气数据。 我从我的网站上收取每个API电话的费用。
问题是当Google抓取我的网站时,它会生成API调用,我会收取费用。 我试图阻止Googlebot触发API调用。这是我尝试过的,它似乎无法阻止API调用。我仍然可以从所有抓取活动中每天接到3000个电话。
<?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>