Using PHP to Password-Protect Folders/Sub-Folders

It is for static page, dynamic page, website, SEO, performance and other web development discussion
ramverma
Posts: 435
Joined: Sat Aug 23, 2014 5:34 pm
Contact:

Using PHP to Password-Protect Folders/Sub-Folders

Postby ramverma » Sat Sep 12, 2015 10:20 am

Hello Forum

I'm both new to this forum AND to PHP. I just started learning PHP several weeks ago.

That being said, I have a site that needs to be accessed only by those with a username/password. I have:

>> A MySQL database with full names, usernames and passwords.
>> HTML code that brings the user to a “Welcome” page to log in
>> PHP code that connects to the MySQL database
>> PHP code that checks the database and redirects the user to the “Resources” page (where choices of tasks are available) or rejects the user if credentials are invalid and prompts him to attempt login again.

Having all this, how do I apply it so a folder and sub-folders are accessible only if the login was successful? The way it is now, all I need do is type in the URL for the “Resources” page (bypassing the login at the "Welcome" page) and I’m in. How do I use the login on the “Welcome” page so it applies to the whole folder?

I know that .htaccess and .htpasswd would protect the folder, but I’m in a learning process (no doubt you can see that) and want to know how to do this.


Return to “PHP, HTML, MYSQL and Web Hosting”

Who is online

Users browsing this forum: No registered users and 1 guest