?
Solved

Problem with http basic authentication

Posted on 2015-01-06
5
Medium Priority
?
117 Views
Last Modified: 2016-05-09
I am having trouble getting basic authentication, so I wrote this simple file which I was hoping would reveal why.

     1  <?php
     2
     3  if (!isset($_SERVER['PHP_AUTH_USER'])) {
     4    header ('WWW-Authenticate: Basic realm="Basic Auth Test"');
     5    header ('HTTP/1.0 401 Unauthorized');
     6    die ("Was the Cancel button pressed?");
     7  }//end if
     8
     9  echo "\nOk, we have a value! Let's dump the \$_SERVER global array!\n\n";
    10  var_dump($_SERVER);
    11  echo "\n\nFinished!\n";
    12
    13  ?>
    14

It should open an 'Authentication Required' window requesting a user name and password, but should accept whatever is entered. However, the window appears as expected, but when the fields are filled and OK is clicked, it vanishes for a very brief time, then reappears. Seems the entries are not being kept in the $_SERVER['PHP_AUTH_USER'] array.

The server is running Centos 6.5 and Plesk 12

I tried running the script on another server with Centos 6.4 with no GUI, and it works fine when I browse it.

Kind of making me crazy. Hope someone can help.

Wayne
0
Comment
Question by:denverwayne
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 16

Expert Comment

by:HagayMandel
ID: 40537777
Use
if(isset($_SERVER['PHP_AUTH_USER'])){
  var_dump($_SERVER['PHP_AUTH_USER']);
}

Open in new window

at the very beginning of the code, to find out what is really kept there.
0
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 total points
ID: 40541763
Is there some reason you have '&lt;' instead of '<' at the beginning?  This is what it should look like.

<?php

if (!isset($_SERVER['PHP_AUTH_USER'])) {
  header ('WWW-Authenticate: Basic realm="Basic Auth Test"');
  header ('HTTP/1.0 401 Unauthorized');
  die ("Was the Cancel button pressed?");
}//end if

echo "\nOk, we have a value! Let's dump the \$_SERVER global array!\n\n";
var_dump($_SERVER);
echo "\n\nFinished!\n";

?>

Open in new window

0
 

Author Comment

by:denverwayne
ID: 40640317
OK, thanks. Finally got it!
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is written by John Gates, CISSP. Gates, the SNUG President-Elect, currently holds the position of Manager of Information Systems at Lake Park High School in Roselle, Illinois.
The well known Cerber ransomware continues to spread this summer through spear phishing email campaigns targeting enterprises. Learn how it easily bypasses traditional defenses - and what you can do to protect your data.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question