Created
March 24, 2009 12:26
-
-
Save rmasters/84058 to your computer and use it in GitHub Desktop.
Antiblock proxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Anti-block proxy | |
* @author Ross Masters <[email protected]> | |
* @package antiblock | |
* @version 0.1 | |
*/ | |
// Bail on empty/unset url | |
if (!isset($_GET['url']) || empty($_GET['url'])) { | |
throw new Exception('No url specified.'); | |
} | |
// Bail on invalid url | |
// @todo Recognises partials? | |
if (!filter_var($_GET['url'], FILTER_VALIDATE_URL)) { | |
throw new Exception('Invalid url.'); | |
} | |
// Start curl handle and retrieve url | |
$ch = curl_init($_GET['url']); | |
curl_setopt($ch, CURLOPT_RETURN_TRANSFER, true); | |
$result = curl_exec($ch); | |
$info = curl_getinfo($ch); | |
curl_close($ch); | |
// Log request | |
$log = fopen('./log.txt', 'a'); | |
fwrite($log, PHP_EOL . serialize(array('time' => time(), 'uri' => $_GET['url'], 'info' => $info))); | |
fclose($log); | |
// Output page | |
header('Content-type: ' . $info['content_type']); | |
echo $result; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment