Skip to content

Instantly share code, notes, and snippets.

@rmasters
Created March 24, 2009 12:26
Show Gist options
  • Save rmasters/84058 to your computer and use it in GitHub Desktop.
Save rmasters/84058 to your computer and use it in GitHub Desktop.
Antiblock proxy
<?php
/**
* Anti-block proxy
* @author Ross Masters <ross@php.net>
* @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