PHP スクリプトで必要な URL を要求し、すべてのリンクとフォーム アクションを書き直して、php スクリプトを指すようにします。URL パラメーターを持つスクリプトへの要求を受信すると、それをリモート サーバーに転送して繰り返します。
すべての JavaScript リクエストをキャッチすることはできません (「プロキシ」の JavaScript 部分を実装しない限り)。
例: ユーザーがhttp://example.com/login.phpをプロキシ フォームに入力します。
ユーザーをhttp://yoursite.com/proxy.php?url=http://example.com/login.phpに送信します
パラメータ " http://example.com/login.php "を urlencode してください。
http://yoursite.com/proxy.phpでは、 http://example.com/login.phpに対して HTTP リクエストを行います。
$url = $_REQUEST['url'];
// make sure we have a valid URL and not file path
if (!preg_match("`https?\://`i", $url)) {
die('Not a URL');
}
// make the HTTP request to the requested URL
$content = file_get_contents($url);
// parse all links and forms actions and redirect back to this script
$content = preg_replace("/some-smart-regex-here/i", "$1 or $2 smart replaces", $content);
echo $content;
/some-smart-regex-here/iは、実際には、リンクなどを解析するために記述する必要がある正規表現であることに注意してください。
この例では、HTTP ボディをプロキシするだけです。HTTP ヘッダーをプロキシすることもできます。PHP5+ では fsockopen() または PHP ストリーム関数 (stream_socket_client() など) を使用できます。