Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have a new b2b vendor that wants to use basic auth via URL.

They want to authenticate like this:

  //URL coming into our server

How can I get the username and password from the URL via my listener.php script?

I have tried setting basic auth headers per the php man page but it pops up a login box, which is not what I need, since these are web services talking to each other, not people:

if (!isset($_SERVER['PHP_AUTH_USER'])) {
     header('WWW-Authenticate: Basic realm="My Realm"');
     header('HTTP/1.0 401 Unauthorized');
     echo '<response><error>No username and password found</error></response>';
 } else {

   //process request if username & password are legit

share|improve this question

closed as off topic by ceejayoz, MadHatter, John Gardeniers, Ward, Magellan Nov 15 '12 at 17:58

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

Using that URL style should present the username and password as Basic Auth credentials. This is a function of whatever software is making the request. Your server needs to be configured to accept (and pass to your application) the credentials received. – voretaq7 Nov 14 '12 at 20:50
up vote 1 down vote accepted

These should wind up in the variables $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW']. You won't see them in $_SERVER['HTTP_HOST'] or anything.

share|improve this answer
It was a server configuration issue. I needed to compile the Apache module in my PHP. Once I did that, the $_SERVER array contained $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW'] Thanks – Slinky Nov 15 '12 at 12:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.