supermerc Posted January 5, 2007 Share Posted January 5, 2007 How do I make it so that you need a password to download a certain file? Link to comment https://forums.phpfreaks.com/topic/32940-password-protected-download/ Share on other sites More sharing options...
HoTDaWg Posted January 5, 2007 Share Posted January 5, 2007 well it depends, what method do u wanna use? Link to comment https://forums.phpfreaks.com/topic/32940-password-protected-download/#findComment-153377 Share on other sites More sharing options...
supermerc Posted January 5, 2007 Author Share Posted January 5, 2007 I dont know, something that works? Link to comment https://forums.phpfreaks.com/topic/32940-password-protected-download/#findComment-153378 Share on other sites More sharing options...
HoTDaWg Posted January 5, 2007 Share Posted January 5, 2007 haha, so is it a [b]file[/b] that you want to protect (like an image or a .doc or .pdf) or a page like an html or php page? Link to comment https://forums.phpfreaks.com/topic/32940-password-protected-download/#findComment-153379 Share on other sites More sharing options...
PC Nerd Posted January 5, 2007 Share Posted January 5, 2007 you could always password the page your on, that starts the download, like with javascript or something simple Link to comment https://forums.phpfreaks.com/topic/32940-password-protected-download/#findComment-153380 Share on other sites More sharing options...
supermerc Posted January 5, 2007 Author Share Posted January 5, 2007 well its a firefox extension, .xpi and I want to lets so you goo to http://mysite.com/thenameofthething.xpi It will ask for the password, if its right then it will let the person download it, if its wrong it wont. Link to comment https://forums.phpfreaks.com/topic/32940-password-protected-download/#findComment-153381 Share on other sites More sharing options...
supermerc Posted January 5, 2007 Author Share Posted January 5, 2007 bump Link to comment https://forums.phpfreaks.com/topic/32940-password-protected-download/#findComment-153702 Share on other sites More sharing options...
marcus Posted January 5, 2007 Share Posted January 5, 2007 [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 https://forums.phpfreaks.com/topic/32940-password-protected-download/#findComment-153714 Share on other sites More sharing options...
fert Posted January 5, 2007 Share Posted January 5, 2007 [code]<?phpif($_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 https://forums.phpfreaks.com/topic/32940-password-protected-download/#findComment-153716 Share on other sites More sharing options...
psychohagis Posted January 6, 2007 Share Posted January 6, 2007 if its linked from a script then theres will work ^^but if you just wanna stop people typing in file names and downloading then then you should look up [b].htaccess[/b] Link to comment https://forums.phpfreaks.com/topic/32940-password-protected-download/#findComment-154168 Share on other sites More sharing options...
Daniel0 Posted January 6, 2007 Share Posted January 6, 2007 In your .htaccess file: [code]<Files "protected_file.xpi"> ForceType application/x-httpd-php</Files>[/code]In your protected_file.xpi: [code]<?phpif($_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 https://forums.phpfreaks.com/topic/32940-password-protected-download/#findComment-154173 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.