Jump to content

Recommended Posts

I am building a web site and have included an admin area where I want to use a username and password that only myself and the admin will be able to use.  I am using the following code, but something is wrong when I put it on my host:

 

<?php

 

$myusername = "myname";

$mypassword = "password";

$areaname = "User's Protected Area";

 

if ($_SERVER["PHP_AUTH_USER"] == "" || $_SERVER["PHP_AUTH_PW"] == "" || $_SERVER["PHP_AUTH_USER"] != $myusername || $_SERVER["PHP_AUTH_PW"] != $mypassword) {

    header("HTTP/1.0 401 Unauthorized");

    header("WWW-Authenticate: Basic realm=\"$areaname\"");

    echo "<h1>Authorization Required.</h1>";

    die();

}

 

?>

 

Can anyone tell me what is wrong with this code?

 

Thank you

Dee

Link to comment
https://forums.phpfreaks.com/topic/63815-protected-areaadmin-area/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.