Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: How to pass apache variable to external auth.php? |
|
Author |
|
rossbcan
Joined: 15 Aug 2018 Posts: 8
|
Posted: Sun 14 Mar '21 16:24 Post subject: How to pass apache variable to external auth.php? |
|
|
Is seems possible to set environmental variables in a location block which are visible in php.
My external authentication (php) sees these variables:
print_r($_SERVER)
Quote: |
Array
(
[PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
[AUTHTYPE] => PASS
[IP] => 192.168.2.1
[URI] => /Downloads/SecureOffice/r13710/packages_x86_64/Packages.gz
[HTTP_HOST] => redacted.org
[PHP_SELF] => /home/e-smith/files/ibays/rossco/license_server/download_auth.php
[SCRIPT_NAME] => /home/e-smith/files/ibays/rossco/license_server/download_auth.php
[SCRIPT_FILENAME] => /home/e-smith/files/ibays/rossco/license_server/download_auth.php
[PATH_TRANSLATED] => /home/e-smith/files/ibays/rossco/license_server/download_auth.php
[DOCUMENT_ROOT] =>
[REQUEST_TIME_FLOAT] => 1615730112.1554
[REQUEST_TIME] => 1615730112
[argv] => Array
(
[0] => /home/e-smith/files/ibays/rossco/license_server/download_auth.php
)
[argc] => 1
)
|
In my authentication location block, I have this:
"RequestHeader set HTTP_X_FORWARDED_FOR %{HTTP_X_FORWARDED_FOR}e\n";"
...which does not show up as [HTTP_X_FORWARDED_FOR] in php
Q - how do I get fpm variable HTTP_X_FORWARDED_FOR in my php authenticator? |
|
Back to top |
|
tangent Moderator
Joined: 16 Aug 2020 Posts: 348 Location: UK
|
Posted: Mon 15 Mar '21 15:54 Post subject: Re: How to pass apache variable to external auth.php? |
|
|
In your configuration code:
rossbcan wrote: | RequestHeader set HTTP_X_FORWARDED_FOR %{HTTP_X_FORWARDED_FOR}e
|
you are setting a request header based on the current value of an Apache variable, whereas your question is the other way round. You're wishing to set an Apache variable, based on a request header, to be picked up by your PHP code.
So try the following instead:
Code: | SetEnvIf HTTP-X-Forwarded-For ^(.+)$ HTTP_X_Forwarded_For=$1 |
Make sure you enable the SetEnvIf module, and note its context is server config, virtual host, directory, and .htaccess - not a location block. I'd put it at the global server level myself. |
|
Back to top |
|
rossbcan
Joined: 15 Aug 2018 Posts: 8
|
|
Back to top |
|
|
|
|
|
|