secure a page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Daron
Forum Newbie
Posts: 11
Joined: Tue Oct 09, 2007 4:50 pm

secure a page

Post by Daron »

How in PHP do you create a page that when you try to open it, it requires a username and password? I feel like this should be simple, but I just can't figure it out.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

A form, some way of validating that the username and password are correct, and a session to determine if they are logged in.
shannah
Forum Newbie
Posts: 13
Joined: Mon Oct 15, 2007 1:01 am

Post by shannah »

As with anything in development there are many ways to accomplish a task.

In addition to PHP form method, you could use Apache .htaccess files for authentication.
http://www.apacheweek.com/features/userauth
This explains how to protect a whole directory.

You can wrap these directives in a Filesmatch directive to only protect a particular file:
http://httpd.apache.org/docs/1.3/mod/co ... filesmatch

Alternatively you can do HTTP authentication (using HTTP headers) directly in PHP:
http://ca.php.net/features.http-auth

Hope this helps a little.

-Steve
Post Reply