PHP and HTTP authentication - enter login and password using filter_input

I am trying to get the user login and password from HTTP authentication in PHP using filter_input, but I get zeros for PHP_AUTH_USER and PHP_AUTH_PW. I did 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'm just wondering why filter_input does not work for these two $ _SERVER keys, but works with the others.

+6
source share
2 answers

Although this does not directly answer your question - since something seems to be happening with an error - a decent solution would be the following:

 $phpAuthUser = filter_var($_SERVER['PHP_AUTH_USER']); 
+2
source

PHP_AUTH_USER are user properties, so they will never be retrieved without $ _SERVER var.

+2
source

Source: https://habr.com/ru/post/957979/


All Articles