Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting basic-auth username in php

Tags:

php

How can I access the apache basic-auth username in a PHP script?

like image 795
Ben Avatar asked Nov 25 '08 09:11

Ben


People also ask

How can I pass my basic auth username and password?

We can do HTTP basic authentication URL with @ in password. We have to pass the credentials appended with the URL. The username and password must be added with the format − https://username:password@URL.

What is $_ SERVER [' Php_auth_user ']?

Once the user has filled in a username and a password, the URL containing the PHP script will be called again with the predefined variables PHP_AUTH_USER , PHP_AUTH_PW , and AUTH_TYPE set to the user name, password and authentication type respectively. These predefined variables are found in the $_SERVER array.

Where are basic auth credentials stored?

You can store your Authorization header values in localStorage or sessionStorage. The value of Authorization header, stored in LocalStorage, will be automatically each time you make HTTP requests.

How can you verify a user's authentication credentials in PHP?

After receiving user authentication details in PHP, it compares the form data with the user database by executing a query by using the connection object. The query binds the username entered by the user via HTML form. Then, it verifies the password hash with the entered password to return the authentication results.


2 Answers

Simply access this variable:

$_SERVER['PHP_AUTH_USER']
like image 98
William Entriken Avatar answered Sep 20 '22 21:09

William Entriken


HTTP Auth in the PHP Manual would be a good starting place.

like image 31
Greg Avatar answered Sep 20 '22 21:09

Greg