passwording a file, in PHP ?

rh71

No Lifer
Aug 28, 2001
52,844
1,049
126
Would like to put an XLS file on a webhost (that supports PHP). Need to give only a couple users access to this file. Can an authentication method be done via PHP ? Anything that will limit access to users with a password is fine...

Not sure how to setup the regular popup password that we usually see on a webhost ... and even so, don't have the authority at that level on this webhost.
 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
The regular auth method is done with .htaccess - for what you want to do, you could just do something like (I haven't tested this):
<?php
if ($_GET["password"] != "password") die("go away");
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment");
$fp = fopen ("foo.xls, "r");
while (!feof ($fp)) {
$buffer = fgets($fp, 32768);
echo "$buffer";
}
?>

Just put foo.xls somewhere that nobody has access to.