File: C:/xampp/htdocs/source/pbnTool/track.php
<?php
// Set the timezone to Taiwan
date_default_timezone_set('Asia/Taipei');
$file = $_GET['file'] ?? '';
$logFile = 'download_log.csv';
// Secure the filename to prevent directory traversal
$file = basename($file);
if (file_exists($file)) {
// Save: Time (Taiwan), Filename, IP, and Referrer
$data = [
date('Y-m-d H:i:s'),
$file,
$_SERVER['REMOTE_ADDR'],
$_SERVER['HTTP_REFERER'] ?? 'Direct/Social'
];
$f = fopen($logFile, 'a');
fputcsv($f, $data);
fclose($f);
// Deliver the file
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="' . $file . '"');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
} else {
header("HTTP/1.0 404 Not Found");
echo "File not found.";
}
?>