I coded a script that when users want to download a file, it shows an advert first and then start the download passing the ID of the file via $_GET. Problem is that if I reach the page with no ID specified (download_file.php instead of download_file.php?id=1, for instance), the page starts the download of the page itself.
<?php
require("/membri/lostlife/mysql.php");
// Variables:
$id = $_GET["id"];
$result = mysql_query("SELECT * FROM Setting WHERE ID = $id");
$row = mysql_fetch_array($result);
$downloads = $row["Downloads"] + 1;
//
switch ($_GET["action"])
{
case "download":
// Download the file:
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=\"$row[Filename]\"");
readfile("/membri/lostlife/setting/$row[Filename]");
// Update the database:
mysql_query("UPDATE Setting SET Downloads = $downloads WHERE ID = $id");
break;
default:
echo "";
header("Refresh: 5; url=?id=$id&action=download");
}
?>
That's my code. What's wrong with it?