我有一個PHP程序連接到網站上的MYSQL數據庫。 單擊鏈接下載文件時,程序將從數據庫中讀取一個整數字段,將其遞增,然後放回數字以計算下載數量。該計劃有效。然而,隨着時間的推移,下載數量似乎會適度增加。網絡機器人可以膨脹下載次數嗎?
下載文件的鏈接後,下載計數是否可以通過網絡機器人增加?如果是這樣,會告訴網絡機器人忽略網站上的下載頁面,使用robots.txt文件解決膨脹計數問題?
這裏是PHP代碼:
function updateDownloadCounter($downloadPath, $tableName, $fileNameField, $downloadCountField, $idField)
{
require("v_config.php");
if(isset($_REQUEST["file_id"]) && is_numeric($_REQUEST["file_id"])) {
try
{
$sql = "SELECT * FROM " . $tableName . " WHERE file_id = " . $_REQUEST[$idField];
$connection = new PDO($dsn, $username, $password, $options);
$statement = $connection->prepare($sql);
$statement->execute();
$result = $statement->fetchAll();
if ($result && $statement->rowCount() == 1)
{
foreach ($result as $row)
{
if(is_file($_SERVER['DOCUMENT_ROOT'].$downloadPath . $row[$fileNameField]))
{
$count = $row[$downloadCountField] + 1;
$sql = "UPDATE " . $tableName . " SET " . $downloadCountField . " = " . $count . " WHERE file_id = " . $_REQUEST[$idField];
$statement = $connection->prepare($sql);
$statement->execute();
$documentLocationAndName = $downloadPath . $row[$fileNameField];
header('Location:' . $documentLocationAndName);
}
}
}
}
catch(PDOException $error)
{
echo $sql . "<br>" . $error->getMessage();
}
}
}