<?php

if (!function_exists('getallheaders'))  {
    function getallheaders()
    {
        if (!is_array($_SERVER)) {
            return array();
        }

        $headers = array();
        foreach ($_SERVER as $name => $value) {
            if (substr($name, 0, 5) == 'HTTP_') {
                $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
            }
        }
        return $headers;
    }
}



if (isset($_GET['check']) && $_GET['check'] == 'yes')
{
	$hs = getallheaders();

	if (isset($hs['Proxy']) || isset($hs['proxy']))
		echo "bad";
	else
		echo "good";
	exit(0);
}


$http='http';
if ($_SERVER['HTTPS'] == 'on')
	$http='https';

$url = "$http://".$_SERVER['HTTP_HOST'].$_SERVER["SCRIPT_NAME"]."?check=yes";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Proxy: evil"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch);
if ($r === false)
	echo curl_error($ch);

if ($r == 'good')
{
	?><b>Good!</b>  Proxy has been filtered out.  No need to do anything<?php
}
elseif ($r == 'bad')
{
	?><b>Bad!</b> You'll need to filter out the proxy header in your configs.<?php
}
else
{
	?>No idea.. something went wrong:<br><textarea cols=80 rows=10><?=$r?></textarea><?php
}


curl_close($ch);


?>
