Password protecting a directory with a custom login page

Hello everyone!
How can I create a login page to protect a directory?

Basically, I want something that works exactly like a .htaccess directory privacy, but where I can style the page with CSS (So not a pop-up, alert box). (So no sign-up page, just a login page with only a “Password” field)

If the user tries to go to a page in the protected directory, and they are not logged in, it will redirect them to the login page.
Thanks!

This is slightly old (I made it about a year ago) and outdated but it works:

1 Like

Thanks! Taking a quick look, it looks like it will work.

It is not necessary for what I want to do, but can I protect multiple pages with the same login page?
Thanks!

You can use this for multiple pages yes. Just copy the protectepage.php (don’t remove the PHP Code at top) and that will protect the page.

2 Likes

@TigerMANEK426, I love the design of it, but it just does not seam to work…


“TBMPRODUCTIONS” is the correct password, right?


Clicking “Enter” just re-loads the page


Everything in one directory

Thanks again!

Did you edit the form action URL to fit with your website?
Could you also share the website your testing it on so that I can try it? Thanks :slightly_smiling_face:

Also if it still doesn’t work after some troubleshooting tell me and i’ll make a new version.

1 Like

Hello @TigerMANEK426, I didn’t see that the first time, but after changing it still does not work.

URL: removed.com - Informationen zum Thema removed.

Code:

I have tried the following for the links:
Note: Replace “pagename” with “auth” of “protectedpage”

removed.com - Informationen zum Thema removed.

“/pagename”

“pagename”

I am still getting the same error where the page will just reload, also, the video background does not seam to work when looking at the site on my iPad.

Ok, I can see this is a HTML error, not a PHP error. The form isn’t actually being submitted.

Could you try changing the form action to /Private/auth and see if that helps?

1 Like

Hi @TigerMANEK426
Not sure what you mean there (I don’t know how HTML forms or PHP work), would I change the code to the following?

Before:

After:

How the heck do you add code blocks? All the options I see don’t show the code correctly!

It still doesn’t seam like its working…

No, I mean change this bit :slight_smile:

1 Like

It worked!
Thanks so much!

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.