PHP Snippet: Reverse Proxy ?

I’m not suffering from Blog Burnout, just a little playstation distraction ;) Actually, I’ve spent a lot of time learning PHP for my potential new project; during this I found the function: file_get_contents, which in turn leads me to ask:

Is it possible to make a PHP Reverse proxy ?

I’m thinking yes, but it wouldn’t be easy. file_get_contents allows you to open a file or even a URL from a PHP script running on your webserver, just this simple thought gave birth to this snippet of code:


if ( $URL == "") {
No URL Given:

Try <a HREF="<?php echo $self; ?>?url="><?php echo $self ;?>?url=</a>
} else {
$PAGE = file_get_contents($URL);

echo "$PAGE";


As you can see it allows a user to send a url , which the server downloads and delivers to their browser. Now before anyone puts this onto a webserver you should be aware of the MASSIVE Security Issue, any user that opens the page can ask the server to open any file, e.g /etc/passwd or a malicious URL.

If you do try it, you’ll find that the page doesn’t look right or links don’t work, or even that pictures have loaded, but they were delivered directly to the browser, not from the server. That’s because no re-writing is taking place (that’s the hard bit) , but with companies like whale & juniper investing huge sums of money in SSL vpns, which is simply a reverse proxy with a bit of ssl tunneling, I don’t suppose it’ll be long ;)