Hi ,
How does a PHP Proxy work ?
I am looking to make a little script which is similar to other php proxies
But how does it actually work ?
Hi ,
How does a PHP Proxy work ?
I am looking to make a little script which is similar to other php proxies
But how does it actually work ?
That's more work than you might think. Simply calling a remote web page and displaying its contents is not enough (that would be readfile('http://google.com')
in the simplest case), you have to rewrite the urls in the html document to point to your own proxy again, you need to be able to process https (or you would be allowing normal access to sensitive data, if the target page needs https) and many others (that have partially been compiled in RFC 3143).
Maybe apache's mod_proxy
has all you need, but if you really want to write one yourself, studying the source code of other projects (like php-proxy) might give you more insight into the matter.
I'm thinking of a PHP Proxy, used to go around AJAX Sane Origin Policy. If you need a real HTTP proxy, the process is much more complex.
Simplest pseudocode:
$_POST['url']
)Note: in this simplest form, you are allowing anyone to access any URL on the Internet through your PHP Proxy; some access control should be implemented (e.g. logged-in users only, depending on what you use the proxy for).