How to prevent users from viewing certain pages?

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
Smudly
Forum Commoner
Posts: 71
Joined: Wed Jun 09, 2010 10:09 pm

How to prevent users from viewing certain pages?

Post by Smudly »

Hi, I need to add some security to some pages and even some directories so users are not able to view them. What do I need to do to prevent users from viewing pages?
User avatar
morris520
Forum Commoner
Posts: 60
Joined: Thu Sep 18, 2008 8:56 pm
Location: Manchester UK

Re: How to prevent users from viewing certain pages?

Post by morris520 »

1: try to read something about HTAccess, e.g. Forbidden page
2: If you want to do it in programming aspect, you can add an index.php to each of your dir. Then write if-statement to redirect them to other pages.

Hope this helps
rhecker
Forum Contributor
Posts: 178
Joined: Fri Jul 11, 2008 5:49 pm

Re: How to prevent users from viewing certain pages?

Post by rhecker »

The method I use to protect directories is the method Morris touched on. Run htpasswd from the Apache BIN directory to encrypt the password. Take the file containing this and put it above the website root, where others cannot access it. Then place an .htaccess file in any directory you want to protect. The contents of this file will look somethng like this:

Code: Select all

authtype basic
authname ADMIN
authuserfile /data/18/1/130/82/78421/user/1745722/cgi-bin/.admin
require valid-user
Here is the url for the htpasswd command line arguments:

http://httpd.apache.org/docs/2.0/programs/htpasswd.html
hag
Forum Newbie
Posts: 10
Joined: Tue Apr 06, 2010 10:51 pm

Re: How to prevent users from viewing certain pages?

Post by hag »

use sessions or the other ideas.. if interested post back and I'll provide more info

I didn't want to include too much if you were going with the other ideas.

Hag

PS I only use htaccess to provide a "window" for web clients before their site goes live, everthing else I use sessions
Post Reply