Jan 8, 2012
tom

Proxy+PHP: filter and process specific proxied requests and responses with PHP scripts

Question

I need to configure a proxy on a machine A in a network X. Then I need to connect a client (smartphone) on this same network X but having the proxy configuration as the one prepared on the machine A. So basically, the smartphone is going to pass through Machine A before reaching internet and receiving the remote response.

I tried with Apache and his mod_proxy.so module.

What I really need to do, it’s that when the client (smartphone) asks for an specific URL (Google i.e.), the Proxy Server have to filter the request and send it to a PHP script programmed to attend the request and send an specific answer to the client (and NOT the remote server response original one). For all the other requests (webs and sites), everything is going to be normal (not filtered by the proxy server).

I tried with a Forward Proxy on Apache, but I just get the tracking on the log access file. Nothing more. I can’t create a “redirection” for specific requests.

Then I thought of a Reverse Proxy, trying to redirect the specific ones to a local place via ProxyPass and ProxyPassReverse. Didn’t worked. Seems that Reverse Proxy only works for local asks to be resolved on the exterior or interior. But not to work for resolving exterior requests to a local ones.

Then I tried to play with mod_ext_filter.so, and played with “SetOutputFilter”, creating a call to php.exe (Windows implementation) and a particular test.php script to print the $_SERVER array, and I managed to view the correct REQUEST_URI from my smartphone (client), printing a file to “C:”.

But then, when script finishes, the client receives no answer. So this doesn’t seems to be the good approach too.

What should I do? Someone talked to me about SQUID and Content Adaptation, but I’m not sure about it.

Answer

Squid with an external redirector will do exactly what you want. You’ll have it rewrite certain requests to point to the PHP script on your local server, while allowing other requests to pass through to the Internet.

An external redirector is simply a small program that receives requests from squid on stdin, rewrites them as necessary, and then returns them to squid on stdout.

Related posts:

  1. Proxy+PHP: filter and process specific proxied requests and responses with PHP scripts
  2. Efficiency of web proxy scripts vs. http proxy?
  3. Reverse proxy HTTP requests using database information
  4. A single php-fastcgi process blocks all other PHP requests
  5. Proxy Access to my Squid Proxy

Leave a comment