Base password for php

Now I have an Apache server that holds folders containing pictures and some home videos. I transferred the port and received it to show the folders when I enter my ip. My only problem is that any user can access it from all over the world. I found this PHP code on the Internet, so I can password protect these files:

<?php // Define your username and password $username = "someuser"; $password = "somepassword"; if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password) { ?> <h1>Login</h1> <form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <p><label for="txtUsername">Username:</label> <br /><input type="text" title="Enter your Username" name="txtUsername" /></p> <p><label for="txtpassword">Password:</label> <br /><input type="password" title="Enter your password" name="txtPassword" /></p> <p><input type="submit" name="Submit" value="Login" /></p> </form> <?php } else { ?> <p>This is the protected page. Your private content goes here.</p> <?php } ?> 

I found a line where it says to post my personal content, but I don’t understand how to do it. im not trying to protect any html or php page trying to protect multiple folders. PS I can do it well, ftping on my server to access files, but I want to be able to also access them from any browser.

+4
source share
1 answer

Try to learn htpasswd and implement it.

You can create the htpasswd file through this . Just enter your username and password and an entry will be created for the htpasswd file. You can use the htaccces Authentication generator to create an htaccess file that will protect your site or directory. This htpasswd generator creates passwords that are hashed using the MD5 algorithm, which means that you can use it for sites hosted on any platform, including Windows and Linux. You can also create htpasswd passwords with PHP on your own server - this method only works on Linux. Learn more about htpasswd files.

Read more about htpasswd from here.

+6
source

Source: https://habr.com/ru/post/1484380/


All Articles