Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP & HTTP authentication - get login and password with filter_input

I am trying to retrieve user login and password from HTTP authentication in PHP, using filter_input, but I get nulls for both PHP_AUTH_USER and PHP_AUTH_PW. I made a test:

$phpAuthUserFV = filter_input(INPUT_SERVER, 'PHP_AUTH_USER');
// gives null

$phpAuthUser = $_SERVER['PHP_AUTH_USER'];
// gives the user login entered

$remoteAddr = filter_input(INPUT_SERVER, 'REMOTE_ADDR');
// gives the remote address

$phpSelf = filter_input(INPUT_SERVER, 'PHP_SELF');
// gives the PHP_SELF value

Tested with PHP 5.5.5 and 5.3.3.

Am I missing something? I am just wondering, why filter_input fails for these two $_SERVER keys, but works with other.

like image 423
Veelkoov Avatar asked Nov 13 '13 10:11

Veelkoov


1 Answers

Although this does not directly answer your question - since there seems to be something buggy going on - a decent workaround would be:

$phpAuthUser = filter_var($_SERVER['PHP_AUTH_USER']);
like image 62
Damien Overeem Avatar answered Sep 28 '22 23:09

Damien Overeem



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!