私のphpスクリプトは、.zipファイルをダウンロードし、カウンターをインクリメントすることになっています。以下のコードでは、URL で渡されたパラメーターが認識されていないため、ファイルをダウンロードする行は何も実行しません。ファイルのダウンロードが機能しない場合、カウントは無限にループし、カウントがインクリメントされます。私のプロバイダーは PHP V5.2 を使用しています。
渡されたパラメーターが機能することを望みますが、タグに「myapp.zip」をハードコーディングしてもかまいません。
作業が完了したら、count.php を呼び出したページに戻る必要があります。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
//$Down=$_GET['Down'];
$Down=$_Post['Down'];
echo "File:" . $Down;?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<!--meta http-equiv="refresh" content="0;url=<?php echo $Down;?>"/-->
<meta http-equiv="refresh" content="0;url=MyApp.zip"/>
</head>
<body>
<?php
$filePath = 'count.txt';
// If file exists, read current count from it, otherwise, initialize it to 0
$count = file_exists($filePath) ? file_get_contents($filePath) : 0;
// Increment the count and overwrite the file, writing the new value<br />
file_put_contents($filePath, ++$count);
// Display current download count
//echo "Downloads:" . $count;
//header("Location: $r.htm");
?>
</body>
</html>
次のように r.htm から呼び出されます。
<form method="post" action="count.php?Down=myapp.zip" style="text-align: center">
<input type="submit" value="Download MyApp">
</form>