Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my website idea I have got a number of pages that should be accessible by the admin only.

Is this a good practice? (amateur alert)

Also how do I protect these pages? I know about

if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || ($_SERVER['PHP_AUTH_USER']!='admin') || ($_SERVER['PHP_AUTH_PW']!='password'))
{// The username/password weren't entered so send the authentication headers
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Admin"');

Is this all I can do?

Also how do I make sure that my website is secure? That is, since I am an amateur, I have this book on PHP and all I have in my PHP script are a few if-else statements and accordingly SQL queries?

Is this how the php script would usually be like or have I just learnt the most basic thing and I'm making use of it more than I should?

share|improve this question
up vote 1 down vote accepted

first of all, do you ave an apache or nginx server ? If so, you can simply protect the directory by a password without the use of a script. A script can be harmfull for protecting an area if you are not used to php and web security.

Keep in mind that your script can be exposed to sql injection, php exploits and alikes.

To answer your question, no, it is not a good practice.


auth http://httpd.apache.org/docs/2.0/howto/auth.html



And a lot on stackoverflow and pro webmasters :-)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.