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?logout=1
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)

How useful was this post?

Click on a star to rate it!

Average rating 4.4 / 5. Vote count: 18

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?