Instantly share code, notes, and snippets.

Embed
What would you like to do?
Small script to detect reverse proxy
<html>
<body>
<script>
var serverport = '<?php echo intval($_SERVER['SERVER_PORT']);?>';
var browserport = window.location.port || (window.location.protocol === 'https:' ? '443' : '80');
var color = (serverport === browserport ? 'green' : 'red');
var text = "<pre style='color:#color'>Server port: "+serverport+"<br>Browser port: "+browserport+"</pre>";
document.write(text.replace("#color",color));
</script>
<pre>
<?php
echo 'IP: '.htmlspecialchars($header.": ".$_SERVER['REMOTE_ADDR'], ENT_QUOTES, 'UTF-8')."\n\n";
$headers = array('X_FORWARDED_FOR', 'X_FORWARDED_PROTO', 'X_FORWARDED_HOST', 'X_FORWARDED', 'FORWARDED', 'CF_CONNECTING_IP');
foreach ($headers as $header){
if(isset($_SERVER['HTTP_'.$header])){
echo htmlspecialchars($header.": ".$_SERVER['HTTP_'.$header], ENT_QUOTES, 'UTF-8')."\n";
}
}
?>
</pre>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment