} } } while ($code && --$mr); curl_close($rch); if (!$mr) { if ($maxredirect === null) { trigger_error('Too many redirects. When following redirects, libcurl hit the maximum amount.', E_USER_WARNING); } else { $maxredirect = 0; } return false; } curl_setopt($ch, CURLOPT_URL, $newurl); } } return curl_exec($ch); } } try { // Use '' al default if (isset($_GET['url'])) { $url = $_GET['url']; unset($_GET['url']); } else { $url = ''; } $proxy = new Proxy(); echo $proxy->run($url, $_GET, $_POST); } catch (Exception $e) { echo 'Error: ' . $e->getMessage(); }
} } } static function run() { $self = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; $path_self = @$_SERVER['PATH_TRANSLATED'] ?: $_SERVER['SCRIPT_FILENAME']; $a = strlen($self); $b = strlen($path_self); $i = 0; while ($self[$a - $i - 1] == $path_self[$b - $i - 1] && $i < 1000) { $i++; } if ($i == 0) { return; } self::$base_url = substr($self, 0, strlen($self) - $i); self::$base_path = substr($path_self, 0, strlen($path_self) - $i); self::$tea = isset($_GET['tea']); $urls = $_REQUEST['url']; if (!is_array($urls)) { $urls = array($urls); } foreach ($urls as $url) { self::process($url); } echo json_encode(self::$cache); } } Proxy::run();