Tobi
Tobi

Reputation: 11

HTTP Basic Auth in RESTful API with PHP

I'm using Fat Free Framework for a small RESTful API. I want the user to authenticate for each requests with HTTP Basic Auth like this:

http://user:sha1(pass)@server.org/[...]

My problem is that I can't get these credentials. Our client (Browser: AJAX Request with jQuery) sends them 100%, but I cant find anything in $_SERVER in PHP.

It looks like Apache doesn't forward user + pass to PHP.

Does anyone know why not? And how I can realize HTTP Basic Auth with PHP?

best regards

Upvotes: 1

Views: 7506

Answers (1)

Ronni Egeriis Persson
Ronni Egeriis Persson

Reputation: 2289

You should be able to find the username and password in $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW'].

There's a great article on php.net on this topic: http://php.net/manual/en/features.http-auth.php

Upvotes: 1

Related Questions