Basic authentication: Difference between revisions
From ULYSSIS documentation
|  (Basic authentication in PHP with CGI workaround) | No edit summary | ||
| (3 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| Because in our webserversetup PHP is installed as a  | Because in our webserversetup PHP is installed as a FastCGI Proxy basic authentication will not work in its usual way. | ||
| There is however a workaround. | There is however a workaround. | ||
| First add a .htaccess file with following code in it: | First add a .htaccess file with following code in it: | ||
| <IfModule mod_rewrite.c>   |  <IfModule mod_rewrite.c>   | ||
| RewriteEngine on \n |  RewriteEngine on \n | ||
| RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L] |  RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L] | ||
| </IfModule> |  </IfModule> | ||
| Next add the following line to your script right before the authentication: | Next add the following line to your script right before the authentication: | ||
| list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':' , base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6))); |  <syntaxhighlight lang="php">list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':' , base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));</syntaxhighlight> | ||
| Now your script should work with basic authentication. | Now your script should work with basic authentication. | ||
| [[Category:Webserver]] | |||
Latest revision as of 16:13, 28 August 2019
Because in our webserversetup PHP is installed as a FastCGI Proxy basic authentication will not work in its usual way. There is however a workaround. First add a .htaccess file with following code in it:
<IfModule mod_rewrite.c> 
RewriteEngine on \n
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>
Next add the following line to your script right before the authentication:
list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':' , base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
Now your script should work with basic authentication.
