Global authentication variable and there use in php
['PHP_AUTH_USER'] and ['PHP_AUTH_PW'] are Global authentication variables used in php with $_Server array.
There use is to authenticate the user by prompt him/her to enter username and password.
Global authentication explain with help of code
$user_name = "hello";
$user_password = "123";
header('WWW-Authenticate: Basic realm="Secured"');
header('HTTP/1.0 401 Unauthorized');
echo "You pressed the Cancel Command";
else if (($_SERVER['PHP_AUTH_USER'] == $user_name) &&
($_SERVER['PHP_AUTH_PW'] == $user_password))
echo "You are authenticated";
echo "You are not authenticated";
In php global authentication we have use a built in array of php that is $_SERVER holding information like paths, headers, and script. Authentication dialog box have two text input field username and password the value the user input are assigned to ($_SERVER['PHP_AUTH_USER']))=$user_name and $_SERVER['PHP_AUTH_USER']=$user_password.
When the browser load the fileds $user_name and $user_password is empty. so on line 3 we check the variable $_SERVER['PHP_AUTH_USER'])) is set or not using the isset function.
On line 4 and line 5 the header function is used to send the alert or message to the client browser to force the client input username and password.
If the line 4 is true, then an authentication request will be sent to the browser. “Secured” can be altered to whatever thing is most wanted on the authentication form. The exit function is stop loading the page if the function is executed.
We use the username and password in the above file only for testing purpose doesn’t use that in the real working environment.
Check Global authentication variables in php