I need to secure a folder. Website was done in PHP. There is an admin area with files like PDF, DOC… so; I cannot protect these files with session variable. Is there a way i
You can't protect it using only PHP, but with the help of a .htaccess file, this is possible.
Create a .htaccess file in the directory you want to protect, and put this in it:
Deny from all
Then, to create a PHP script to access the files, you can do something like this:
// Add user authentication code
$name = 'protected_dir/file.pdf';
$fp = fopen($name, 'rb');
header("Content-Type: application/pdf");
header("Content-Length: " . filesize($name));
fpassthru($fp);
exit;