Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Image Proxy File for vBulletin IMG BBCode - IMTips.co
<?php
$salt = 'XXXX'; //Salt that was used to send hash param
$url = urldecode($_REQUEST['u']); // URL encoded parameter
if (!$url) die('Invalid Request.');
// We check hash to keep hackers out.
$hash = md5($salt.$url.$salt);
if ($_REQUEST['h'] != $hash) die('Invalid Request.');
//Start the Curl session
$session = curl_init($url);
curl_setopt($session, CURLOPT_HEADER, true);
curl_setopt($session, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($session, CURLOPT_TIMEOUT, 3);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
list( $header, $contents ) = preg_split( '/([\r\n][\r\n])\\1/', curl_exec( $session ), 2 );
// Split header text into an array.
$header_text = preg_split( '/[\r\n]+/', $header );
// Cache for 10 days
header("Cache-Control: public, max-age=864000");
header("Pragma: public");
header('Expires: '. gmdate('D, d M Y H:i:s \G\M\T', time() + 864000));
// Propagate headers to response.
foreach ( $header_text as $header ) {
if ( preg_match( '/^(?:Content-Type|Content-Language|Set-Cookie):/i', $header ) ) {
header( $header );
}
}
echo $contents;
curl_close($session);
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment