我有一個腳本來給出一個獨特的下載鏈接。下面:防止腳本再次在php中運行
問題是,當我刷新頁面時,它會產生另一個鏈接。
我試圖header
,但我想:
- 展現出獨特的下載鏈接
- 如果刷新頁面,重定向或
echo 'Only one download per IP!
類似的東西。 代碼是
<?php
//connect to the DB
$resDB = mysql_connect("sql213.byethost10.com", "user", "pass");
mysql_select_db("Nice try", $resDB);
function createKey()
{
//create a random key
$strKey = md5(microtime());
//check to make sure this key isnt already in use
$resCheck = mysql_query("SELECT count(*) FROM downloads WHERE downloadkey = '{$strKey}' LIMIT 1");
$arrCheck = mysql_fetch_assoc($resCheck);
if ($arrCheck['count(*)']){
//key already in use
return createKey();
} else {
//key is OK
return $strKey;
}
}
//get a unique download key
$strKey = createKey();
//insert the download record into the database
mysql_query("INSERT INTO downloads (downloadkey, file, expires) VALUES ('{$strKey}', 'fernanfloo-OMG.zip', '".(time()+(60*60*24*7))."')");
?>
<html>
<head>
<title>Descargar Fernanfloo OMG sonido</title>
</head>
<h1>By Skyleter</h1>
<p>Su link de descarga es:</p>
<strong><a href="download.php?key=<?=$strKey;?>">download.php?key=<?=$strKey;?></a></strong>
<p>Link caduca en 7 días..</p>
</html>
PS:header
的工作,但正如我所說的,我想展現出獨特的下載鏈接,且僅當用戶在刷新頁面重定向。 (每次重定向到一個頁面)
哦,謝謝!我將在明天嘗試:D,同樣在'$ ip =「203.146.92.56」;',203.146.92.56 <是一個例子no?我需要用其他東西替換該IP或將其留空? – Skyleter
這是一個例子,你需要用用戶的IP地址替換它。 –