Automatic detection of server proxy settings in PHP

I have a PHP script that is running on a windows server. The script creates a soapclient object that can be given proxy_host and proxy_port. Rather than hard-coding these values ​​or making them a config option, I would like the PHP script to automatically detect the local server proxy settings so that if they change or if the script is running on another server, it just works. Does anyone know how to do this in PHP.

0


a source to share


2 answers


I don't think this is currently possible given the wide range of possible proxy configurations. Typically, components (like payment gateways) provide configuration options for proxy information (usually in the php.ini file) where you can set them. Otherwise, if you are working in a Nix based environment, you can try to get the environment settings for the current user using the following method:

http://us.php.net/manual/en/function.getenv.php



This way, if the server user changes the proxy settings, your script can pick it up and try to use it.

0


a source


It's a bit crazy and you probably don't want to. But in win32, you can write a php addon to get the WinHttpGetIEProxyConfigForCurrentUser () value.



Alternatively, with some more research, you can probably find the registry values ​​and then query them using win32std.

0


a source







All Articles