There many ways of performing authentication over the web.
You can use a token and pass it as a special header. This is commonly done with API tokens.
You can also use a cookie to store a session token. This is common for webservers that have
a database session in the backend.
One simple method is to use HTTP Basic Access Authentication. This involves adding a header that contains your username
and password. The proper format for the header is:
Authorization: Basic XXXXXX
Where XXXXXX
is your credentials in the form of username:password
with base64 encoding.
PHP automatically decodes and splits the username and password into special named constants:
PHP_AUTH_USER
with the username as a plain-text string
PHP_AUTH_PW
with the password as a plain-text string
We will look at how to restrict a page using HTTP basic authentication in PHP.