<?php
if(substr($_REQUEST['url'],0,4)=='http') { // if the passed url is an http page
$url = $_REQUEST['url'];
$purl = parse_url($url); // parsed url
$proxy = $_REQUEST['proxy'];
// if the url contains a query and/or a bookmark, pick them up
$query = '';
if($purl['query'] != '') {
$query = '?' . $purl['query'];
}
$fragment = '';
if($purl['fragment'] != '') {
$fragment = '#' . $purl['fragment'];
}
// check if the referring url is already through the proxy
if(substr($purl['host'], -strlen($proxy)) == $proxy) { // if it is, return to the same url
$redir_host = $purl['host'];
}
else { // otherwise, append the proxy
$redir_host = join('.', array($purl['host'], $proxy));
}
// construct the redirect url
$redir_url = join(array($purl['scheme'], '://', $redir_host, $purl['path'], $query, $fragment));
// redirect
header("Location: $redir_url");
}
else {
// show the info page
include('info.php');
}
?>