On some cases, we just want to password protect our page without including the hassle of heavy frameworks (like Laravel, Yii, Symfony etc) and databases. This solution works without any database and have credentials hard-coded in authentication file. You can add or modify accounts by changing php array values. Refer comments inside file for configuration options.
Download basic authentication include file here.
(save it as auth.php)
Step 1) Include “auth.php” file on page which need to be password protected. Include before any output / echo and at start of code. Adjust include path accordingly where you place the file.
Step 2) Configure user/pass by editing auth.php – e.g. ‘username’ => ‘password’. You can also set after logout url. e.g. your login page url.
Result: Now when you access protected page, you will get following login screen. Entering user/password will allow you the access.
To Logout, access same grid page with logout=1 query-string param. e.g. https://example.com/grid.php?
Feel free to change the appearance by modifying css files and hacking html code.
Download basic authentication include file here.
(save it as auth.php)