Set a password to access an FTP folder

How to make an area of ​​our site private by inserting a control with htaccess

I’m working on the possibility of creating a medical record so that it can be handed over to any doctor in case of an emergency. There are some valid apps on the Play Store but the idea of ​​having to give your smartphone to the doctor is not ideal.

The idea that came to me was to dedicate a folder on my personal site, with private access that requires authentication after entering a username and password to protect the area, so that the doctor only needs a computer with a internet to have all my documentation, even if I’m not conscious.

Let’s proceed

Let’s create the folder we want to make private in our domain, calling it whatever we want. Inside we are going to create 2 files

  • .htaccess
  • .htpasswd

Inside .haccess we will have to write the following lines

AuthName "Protect area"
AuthType "Basic"
AuthUserFile /path/to/.htpasswd
Require valid-user

AuthUserFile must indicate the exact location of our .htpasswd, and to identify it we just need to create a .php file in the same location where we inserted the .htpasswd file, and paste the following syntax inside

<?php echo dirname(__FILE__); ?>

We open the file from the browser and copy its contents.

At this point we must insert in the .htpasswd file all the users that can be identified in the folder, one per line. We can use any online tool where we will enter the user and password in clear text, after which we will copy the line generated by the tool into our file.

We finished.

It will be enough for us to attempt access to the folder to see us request a username and password in order to view it.

We periodically check the functioning of the links in our articles. If you notice any links that do not work, please let us know in the comments. If you enjoyed the article consider supporting the blog with a small donation. Thank you. Patreon / Ko-fi / Liberapay / Paypal

Leave a Reply

Your email address will not be published. Required fields are marked *