Question

I am doing this with PHP and would like to know a way to setup PHP_AUTH_USER, PHP_AUTH_PW, HTTP_X_USERNAME, HTTP_X_PASSWORD from request headers.


When I set the request header as:

Authorization: Basic myuser:mypass

it gives some strange values:

[PHP_AUTH_USER] => k
[PHP_AUTH_PW] => �j�����

But when i set it this way:

Authorization: Basic bXl1c2VyOm15cGFzcw== 

it returns:

[PHP_AUTH_USER] => myuser
[PHP_AUTH_PW] => mypass
Was it helpful?

Solution

When Basic is used for the Authorization header, the authentication information is username:password in Base64 encoding.

PHP only sets the PHP_AUTH_USER and PHP_AUTH_PW fields from the Authorization field. The HTTP_X_USERNAME and HTTP_X_PASSWORD fields relate to the X-Username and X-Password headers (not) sent by the client, ie. PHP sets them if it gets them with the request.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top