Jump to content

Recommended Posts

With register globals off, this doesn't work:

 

<?
/* Check for values in $PHP_AUTH_USER and $PHP_AUTH_PW */

if ((!isset($PHP_AUTH_USER)) || (!isset($PHP_AUTH_PW))) {

    /* No values: send headers causing dialog box to appear */
    header('WWW-Authenticate: Basic realm="My Private Stuff"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Authorization Required.';
    exit;

} else if ((isset($PHP_AUTH_USER)) && (isset($PHP_AUTH_PW))){

    /* Values contain some values, so check to see if they're correct */

    if (($PHP_AUTH_USER != "revelation") || ($PHP_AUTH_PW != "genesis")) {
       /* If either the username entered is incorrect, or the password entered is incorrect, send the headers causing dialog box to appear */
       header('WWW-Authenticate: Basic realm="The test of security page"');
       header('HTTP/1.0 401 Unauthorized');
       echo 'Authorization Required.';
       exit;
    } else if (($PHP_AUTH_USER == "revelation") || ($PHP_AUTH_PW == "genesis")) {
       /* if both values are correct, print success message */
       echo "<P>You're authorized!</p>";
    }
}
?> 

 

If I turn register globals on, it works fine, but I see that having it on is some kinda security risk or something, so what can i do? Does anyone have a basic way to password protect a file using php that doesn't need register globals on?

 

Thanks for your help.

Link to comment
https://forums.phpfreaks.com/topic/38244-register-globals-question/
Share on other sites

Thanks btherl, what you suggested worked perfectly. I might need more help on this project. Specifically, I want to link multiple pages together, and have them all secured in this sort of way. Maybe there is a better way? I don't want people to have to log in every page though. Once they pass the login, it would be nice if they stayed logged in until they close their browser.

Well, I'm obviously no professional when it comes to php, but i put a link in the page to another page that I copy and pasted the same php password protection code as above, and it didn't make me type in the password again when i tested it, so im assuming that its going to work perfectly for what i had in mind. I do a website for free for some dood that smuggles Bibles into China, and he wants a secure area of his website so he can post special pics and message to donors and such. I don't know how 100% secure this is the way i have it, but I'm willing to listen if you have any better suggestions. I guess he might be paranoid about the Chinese govt ya know. Thanks for your time!

Not that I condone any illegal activities, but plain http authentication isn't a good level of security against a government.

 

I would use SSL (https) as well, and ensure that the URLs (including any "get" arguments) don't contain any sensitive information.  Still not perfect, but a vast improvement over unencrypted http.

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.