1

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
  http://usernametext:[email protected]/listener.php

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>';
     exit;
 } else {

   //process request if username & password are legit

}
1
  • 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, 2012 at 20:50

1 Answer 1

1

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.

1
  • 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, 2012 at 12:58

Not the answer you're looking for? Browse other questions tagged .