Jump to content

Password Protected Download


supermerc

Recommended Posts

[code]
<?php
$password = "YOUR PASSWORD";
$act = $_POST['act'];
$file = $_POST['file'];
$get = $_GET['act'];

if(!isset($act)){
echo "<form name=go method=post action=filename.php>";
echo "password: <input type=password name=pass>\n";
echo "<select name=file><option value=1>File description</option></select>";
echo "<input type=hidden name=act value=dl>\n";
echo "<input type=submit value=go>\n";
echo "</form>";
die();
}

if($act == dl && isset($_POST[password])){
if($_POST[password] != $password){
echo "Bad pass!";
die();
}else {
switch($file){
case 1:
$filename = whatever.xpi;
break;
case 2:
$filename = whatever.what;
}
header("Location: filename.php?act=download&file=$filename");
}
}else {
die("Bad password");
}

if($get == download && isset($file)){
header("Location: somerandomfolder/$filename");
die();
}else {
die();
}

?>
[/code]
[code]<?php
if($_POST['password']=="")
{
echo "<form method=\"post\" action=\"{$_SERVER['PHP_SELF']}\'>";
echo "<input type=\"password\" name=\"password\"><input type=\"submit\"></form>";
}
else
{
if($_POST['password']==="password");
{
header("Content-type: xpi_mime");
readfile("xpifile);
}
}
[/code]
that should work
In your .htaccess file: [code]<Files "protected_file.xpi">
ForceType application/x-httpd-php
</Files>[/code]
In your protected_file.xpi: [code]<?php
if($_SERVER['PHP_AUTH_USER']=="admin" && $_SERVER['PHP_AUTH_PW'])
{
$real_file = "real_file.xpi";

header("Content-type: application/x-xpinstall");
header("Content-length: ".filesize($real_file));
readfile($real_file);
}
else {
header('WWW-Authenticate: Basic realm="protected_file.xpi"');
header('HTTP/1.0 401 Unauthorized');
echo 'Access denied';
exit();
}
?>[/code]

Make sure to place the actual file outside of the document root so people can't access it directly.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.