ファイル URL、ダウンロード カウンター .TXT ファイル URL、およびダウンロード後のリダイレクト リンクを受け取る単純なダウンロード ページがあります。これはすべて、PHP 引数を介して送信されます。問題は、誰かがダウンローダにスパムを送信し、カウントを台無しにしていることです。ダウンロード カウンターに上限を設けて、ダウンロード可能なアイテムごとに各アドレスから 3 ヒットしかカウントしないようにします。
PHP のみで、MySQL データベースなしでこれを実行できるようにする必要があります。これには理由があります。私のデータベース サーバーはゴミで信頼性が低く、カウンターをダウンさせることはできません。
これは私の現在のダウンローダー PHP ファイルです。詳細については、この PHP ファイルは、 TXT ファイルをカウントする各ダウンロード/counter
のディレクトリを含む独自のフォルダーにあります。/counter/data
これらのファイルには、整数値が 1 つだけ格納されます。
<?
//Retrieve downloadable file URL
$c_url = urldecode($_GET['url']);
//retrieve redirect page URL
$c_page = urldecode($_GET['page']);
//Retrieve download counter TXT URL
$c_file = "../" . $_GET['file'];
?>
<!-- Set up simple styles -->
<head>
<style type="text/css">
body{
background: url("../images/background.png");
color: #ffffff;
}
</style>
</head>
<!-- Creates download file URL in hidden iFrame -->
<iframe src="<?echo $c_url;?>" id="hiddenFrm" style="display:none;" frameborder="0"></iframe>
<body>
<center>
<h1>Your download is starting</h1><br>
<p>You should be redirected momentarily...<br>
<?
<br><br>
if (file_exists($c_file))
{
//Add one value to the counter file
file_put_contents($c_file, ((int) file_get_contents($c_file)) + 1);
//Set an automatic redirect for the page (Return home)
?>
<meta http-equiv="refresh" content="0;url=<?echo $c_page;?>" />
<?
//Display information about the download, and alternate exits to the page
if ($c_url != "")
{?>
<b><a href="<?echo $c_url?>">Click here</a> if the download did not start.<br><br>
<a href="<?echo $c_page?>">Click here</a> if this page does not close after your download.</b></p>
<?}
else
{
?>
<b><a href="<?echo $c_page?>">Click here</a> if you are not redirected automatically</b></p>
<?
}
}
else
{
//In case our counter file is improperly specified
echo "<br><br><br>Error, the counter file was not found!";
}
?>
</center>
</body>
私の質問は簡単です: 各製品をダウンロードした人の IP アドレスを保存し、PHP のみを使用してデータベースを使用せずに、ダウンロード カウンターがそのアドレスから 3 つ以上のダウンロードをカウントしないようにするにはどうすればよいですか?
助けていただければ幸いです。
編集: 上で述べたように、データベースを使用できません。また、2 つのソリューションに興味がありますが、それらを機能させる方法がわかりません (コード例を探しています)。1 つは Cookie で、もう 1 つはデータベースとして機能するテキスト ファイルです。