Using PHP to get real ip address and complete url

<?php
function get_ip() {
	if ($_SERVER) {
	
		 if ($_SERVER["HTTP_X_FORWARDED_FOR"] ) {
			$realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
		 } elseif ( $_SERVER["HTTP_CLIENT_ip"] ) {
			$realip = $_SERVER["HTTP_CLIENT_ip"];
		 } else {
			$realip = $_SERVER["REMOTE_ADDR"];
		 }
	
	} else {
	
		 if ( getenv( 'HTTP_X_FORWARDED_FOR' ) ) {
			$realip = getenv( 'HTTP_X_FORWARDED_FOR' );
		 } elseif ( getenv( 'HTTP_CLIENT_ip' ) ) {
			$realip = getenv( 'HTTP_CLIENT_ip' );
		 } else {
			$realip = getenv( 'REMOTE_ADDR' );
		 }
	}
	
	return $realip;

}

echo get_ip(); 

?>  
<?php
function getUrl(){
	$url="http://".$_SERVER["HTTP_HOST"];

	if (isset($_SERVER["REQUEST_URI"])){
		$url.=$_SERVER["REQUEST_URI"];
	} else {
		$url.=$_SERVER["PHP_SELF"];
	 if (!emptyempty($_SERVER["QUERY_STRING"])){
			$url.="?".$_SERVER["QUERY_STRING"];
		}
	}

	return $url;
}

echo getUrl();

?>
affiliate_link
Share this Post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

No Responses to “Using PHP to get real ip address and complete url”

Leave a Reply:

Name (required):
Mail (will not be published) (required):
Website:
Comment (required):
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>