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]
Link to comment
Share on other sites

[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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.