How can I restrict access to a .php page?

I have PHP5 running on Windows 2003/IIS6. I need to restrict access to a certain .php page to a single user.  How can I best accomplish this task?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dear Avsc.

There is a really simple work around to this problem.

Basically, if you only have one user, you can do this:

      if ($_POST['action'] == "login"){
            if ($_POST['password'] == "PASSWORD"){
            $icp = true;

Then at the top of your page body (Just below <BODY> tag), add this:

<? if($_COOKIE['UserLoggedIn'] != "235c7n8ob72n45v8n2mc8nc2p96by2cc025y8n75c0bnv3860c80"){ ?>
<form id="login" name="login" method="post" action="">
        <input name="action" type="hidden" id="action" value="submit" />
      Login to access this page:
      <input name="password" type="password" class="text" id="password" />
         <input name="Submit" type="submit" class="text" value="Login" />
        <? if ($icp == true){ ?>
        <? } ?>
<? }else{ ?>

Then you put your body here, then lastly, end the page with <? } ?> to end the if fucntion started earlier on.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Another solution without cookie

include this php code at the beginning of your php file. Just change the the password to whatever you want!!

// Authenticate                                                            //


if (!isset($PHP_AUTH_USER) && !isset($PHP_AUTH_PW)) {
   Header("WWW-Authenticate: Basic realm=Authenticate");
   echo "Authentication required!";  
if ($PHP_AUTH_USER == '') {
   Header("WWW-Authenticate: Basic realm=Authenticate");
   echo "Authentication required!";
if ($PHP_AUTH_USER != 'yourUserid' || $PHP_AUTH_PW != 'yourPassword') {
   Header("WWW-Authenticate: Basic realm=Authenticate");
   echo "Authentication required!";    
AFAIK $_SERVER["PHP_AUTH_PW"] is not guarateed to be set by the server, depends on the web server
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.