PHP – HTTP authentication

  Web Hosting, PHP

Attention: The following instructions do not apply if you are using HTTP authentication by using htaccess and htpasswd files. This applies to the using of global variables PHP_AUTH_USER and PHP_AUTH_PW in PHP.

On our webhosting we are using PHP in FastCGI mode, where these required headers in PHP are not transmitted. There is necessary a little help with it.

1. In the file /www/.htaccess on FTP paste the following code to the beginning:

RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

2. Edit your PHP application so that before checking the login (before controlling variables PHP_AUTH_USER a PHP_AUTH_PW) enter the following command, which completes the missing global variable:

list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])
  = explode(':' , base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));

For more information, visit the following link, where the procedure was taken:
HTTP Authentication with PHP running as CGI/SuExec

Děkujeme za zpětnou vazbu!