Basically, what you are trying to do is create a proxy, in PHP ?
Well, that will not be such an easy tak, I'm afraid : you will have to find every links in the HTML content, and rewrite them one by one... And that for those which you want rewritten (probably not all, so)
A few ideas :
- You could try doing this with a couple regex... That'll end up quite messy...
- Same with str_replace and the like...
- Maybe with
DOMDocument::loadHTML
, some DOM and XPath manipulations... But that's probably be hell on earth too...
So, no miracle idea in PHP, I'm afraid :-(
I have not tried it myself, but if you are working with Apache and you are admin of your server, maybe Apache's mod_proxy_http
and mod_proxy
could help you (not sure, though)
Speaking about a PHP Proxy, maybe you could take a look at some existing software that seem to already do the kind of stuff you want.
For instance :
There might others, btw...
Quoting the page of Glype :
Glype proxy script is a free-to-use,
web-based proxy script written in PHP.
Similar to a typical proxy server, a
web-proxy script downloads requested
web pages and files and forwards them
back to the user. The service is
provided by a web page itself, which
allows instant access to the proxy
without editing your browser
connection settings.
Unfortunatly, the demo page doesn't seem to be working right now :-(
I have not looked into what those can do... But maybe they might help you ;-)
ie, there might be some ideas in their code-source that you could base your script upon ?