2

I was always using an authentication on PHP that worked perfectly. Looks like this:

function login()
{
    header('WWW-Authenticate: Basic realm="Acceso restringido."');
    header('HTTP/1.0 401 Unauthorized');
    echo "Acceso restringido.\n";
    exit;
}


if (!isset($_SERVER['PHP_AUTH_USER'])) {
    login();
} else {
    if ($_SERVER['PHP_AUTH_USER'] == 'test' && $_SERVER['PHP_AUTH_PW'] == 'test1') {
   } else {
        login();
    }
}

However, I changed hosts to ipage.com and now I get the user/pass prompt window but it never takes the user/pass assigned. It keeps on prompting for user/pass.

I read something about CGI but did not get whether this method is not usable in PHP configured as CGI. Is there any alternative?

9
  • 1
    I think it is a serious security issue that you have the credentials right in the php-code! You should either use bcrypt or use authentication through .htaccess. Commented Jul 17, 2013 at 15:08
  • 3
    do a var_dump($_SERVER) to see what you're getting in those two server vars. PHP in cgi mode only has trouble with this stuff if you're running under the IIS web server. Commented Jul 17, 2013 at 15:13
  • @MarcB - I var dumped and the PHP_AUTH_USER and PHP_AUTH_PW don't even show as variables... Commented Jul 17, 2013 at 15:19
  • 1
    PHP Version 5.2.17 | and API is CGI | and stackoverflow.com/questions/7053306/… Commented Jul 17, 2013 at 15:26
  • 1
    If you are lucky, your host allows custom .htaccess (assuming an Apache server). You can use it to implement your HTTP authentication. Here is a good starting point. Commented Jul 17, 2013 at 15:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.