Using .htaccess 












Using .htaccess/.htpasswd Password Protection 





Coding Tips 








Uploads and Downloads 



Mail 
see it on this page





Working with Images 


Frequently Requested Website Functionality 
see it on this page
see it on this page
see it on this page
see it on this page











Using PHP 




Website Managment 








Other Tips 









Tracking and Securing Downloads
If you want to track or secure downloads from your website, try this script. This script will send you an email, write to a log file, or both, every time you have a download. Now you can track what file was downloaded and who did the download.
<?php
/*
This script can send an email and/or make an entry in a log file
There are two variables below - one for an email address and one for a log file
Set both vraiables to the values you want to use
If you do not want either an email or log entry, comment out the respective line
For example, if you do not want an email sent, put a // in front of the $emailAddress line - same for the $logFile line
*/
$emailAddress = "mail@yourdomain.com";
$logFile = "download.log";
$directory = "downloads/"; // the relative directory that has the downloads - can be ./ for the current directory
putenv('TZ=EST5EDT'); // eastern time
// change nothing below this line
$filename = $_GET['file'];
$path = "$directory$filename";
if(file_exists($path) AND substr_count($filename,"/") == "0") {
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=$filename");
header("Content-Length: ".filesize($path));
readfile("$path");
if (isset($emailAddress)) {
$message = "File name: ".$filename."\n\n";
$message .= "Time of the download: ".date(" F d h:ia")."\n\n";
$message .= "Browser: ".$_SERVER['HTTP_USER_AGENT']."\n\n";
$message .= "Page Requested: ".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."\n\n";
$message .= "Referer: ".$_SERVER['HTTP_REFERER']."\n\n";
$message .= "IP Address: ".$_SERVER['REMOTE_ADDR']."\n\n";
$message .= "Hostname: ".gethostbyaddr($_SERVER['REMOTE_ADDR'])."\n\n";
mail($emailAddress,"Download notification",$message,"From: Website <>");
}
if (isset($logFile)) {
$downloadLogRecord = $filename."||".$_SERVER['REMOTE_ADDR']."||".gethostbyaddr($_SERVER['REMOTE_ADDR'])."||".date('Y-m-d H:i:s')."\r\n";
@file_put_contents($logFile,$downloadLogRecord,FILE_APPEND|LOCK_EX);
}
}
?>
