Jump to content

Detecting Proxies


driz

Recommended Posts

Hi, I've been playing with this code, that gets the users REAL ip address:

<?php	function getRealIpAddr() {		if (!empty($_SERVER['HTTP_CLIENT_IP'])) { //check ip from share internet			$ip=$_SERVER['HTTP_CLIENT_IP'];		}		elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { //to check ip is pass from proxy			$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];		}		else {			$ip=$_SERVER['REMOTE_ADDR'];		}		return $ip;	}?>

How can I edit this code so that IF the user is using a proxy I can show an error message such as 'Not allowed to access this page using Proxies' and if they are just using a normal everyday ip then no error will occur. I'm guessing I just replace the $ip variables with my message. But I want an efficient way of doing this, such as showing a whole page BUT not redirecting just showing the error page instead, like what happens if you get a 404, you dont redirect rather you just get the error page on that the problomatic URL. Thanks.

Link to comment
Share on other sites

Or you could send a 400-series header, but you have to do that before output.

Link to comment
Share on other sites

header("HTTP/1.0 403 Forbidden");

That will send a 403 Forbidden header.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...