note 108132 added to features.http-auth
| From: | kazakevichilya at gmail dot com | Date: | Fri, 30 Mar 2012 20:20:24 +0000 |
| Subject: | note 108132 added to features.http-auth | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-186922@lists.php.net to get a copy of this message | ||
In case of CGI/FastCGI you would hot be able to access PHP_AUTH* info because CGI protocol does not
declare such variables (that is why their names start from PHP) and server would not pass them to
the interpreter. In CGI server should authenticate user itself and pass REMOTE_USER to CGI script
after it.
So you need to "fetch" request headers and pass them to your script somehow.
In apache you can do it via environment variables if mod_env is installed.
Following construction in .htaccess copies request header "Authorization" to the env
variable PHP_AUTH_DIGEST_RAW
SetEnvIfNoCase ^Authorization$ "(.+)" PHP_AUTH_DIGEST_RAW=$1
You can now access it via $_ENV.
Do not forget to strip auth type ("Digest" in my case) from your env variable because
PHP_AUTH_DIGEST does not have it.
If mod_env is not installed you probably have mod_rewrite (everyone has it because of "human
readable URLs").
You can fetch header and pass it as GET parameter using rewrite rule:
RewriteRule ^.*$ site.php?PHP_AUTH_DIGEST_RAW=%{HTTP:Authorization} [NC,L]
Here HTTP request header Authorization would be acessible as PHP_AUTH_DIGEST_RAW via $_GET.
---
If you use ZF you probably use Zend_Auth_Adapter_Http to auth user.
It takes Authorization info using "Zend_Controller_Request::getHeader"
This method uses apache_request_header which is likely not to be accessible in old CGI/FastCGI
installations or _$_SERVER['HTTP_<HeaderName>] , so you need to put your authentication
data, obtained via _GET or ENV to
_$_SERVER['HTTP_AUTHORIZATION'].
It will make ZF work transparently with you solution and I believe any other framework should work
also
----
Server IP: 69.147.83.197
Probable Submitter: 217.148.215.10
----
Manual Page -- http://www.php.net/manual/en/features.http-auth.php
Edit -- https://master.php.net/note/edit/108132
Del: integrated -- https://master.php.net/note/delete/108132/integrated
Del: useless -- https://master.php.net/note/delete/108132/useless
Del: bad code -- https://master.php.net/note/delete/108132/bad+code
Del: spam -- https://master.php.net/note/delete/108132/spam
Del: non-english -- https://master.php.net/note/delete/108132/non-english
Del: in docs -- https://master.php.net/note/delete/108132/in+docs
Del: other reasons-- https://master.php.net/note/delete/108132
Reject -- https://master.php.net/note/reject/108132
Search -- https://master.php.net/manage/user-notes.php