September 21, 200917 yr Hey webdesigners, I am currently in the progress of developing a File upload system which is all working out good so far but I was wondering if anyone knows a sufficient way to put a Password on a file with PHP before it proceeds to open in your web browser. So let's say you have a file named instructions.txt and by clicking the file link it would simply open in your window as a text file, but I want my browser to ask its users to fill in a password first before it proceeds. Mainwhile I will try to solve this problem but I look forward to your suggestions! Thanks in advance, Raphisto
September 21, 200917 yr you would need to put the file contents in a php file, the best way would be to use php includes e.g <?php include('file.txt'); ?> to add a password, you can use a general password or use mysql to have it in the db index.php <?php echo '<form method="post" action="file.php"> <label>Enter the password to the file</label><br /> <input type="text" name="pass"><br /> <input type="submit" value="submit">'; file.php <?php $pass=password; if ($_post['pass'] == $pass) { include ('file.txt'); } else { echo 'Password is wrong, try again <br /> <form method="post" action="file.php"> <label>Enter the password to the file</label><br /> <input type="text" name="pass"><br /> <input type="submit" value="submit">'; } ?> That may not be 100% perefect as i haven't tested it but it should be ok
Create an account or sign in to comment