Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[PHP] How to put a password on a file.

Featured Replies

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

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.