Jump to content

getIP function


acctman

Recommended Posts

are these all the combinations for getting a users IP

 

function getIP() {
        if (getenv("HTTP_CLIENT_IP")) $ip = getenv("HTTP_CLIENT_IP");
        else if(getenv("HTTP_X_FORWARDED_FOR")) $ip = getenv("HTTP_X_FORWARDED_FOR");
        else if(getenv("REMOTE_ADDR")) $ip = getenv("REMOTE_ADDR");
        else $ip = "UNKNOWN";
        return $ip;
        }

Link to comment
https://forums.phpfreaks.com/topic/117082-getip-function/
Share on other sites

$_SERVER

<?php
function getip()  
{	
	if (isset($_SERVER)) {		
		if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {  			
			$ip_addr = $_SERVER["HTTP_X_FORWARDED_FOR"]; 		
		} elseif (isset($_SERVER["HTTP_CLIENT_IP"])) {  			
			$ip_addr = $_SERVER["HTTP_CLIENT_IP"]; 		
		} else { 			
			$ip_addr = $_SERVER["REMOTE_ADDR"]; 		
		}	
	} else { 		
		if (getenv('HTTP_X_FORWARDED_FOR')) {  			
			$ip_addr = getenv( 'HTTP_X_FORWARDED_FOR' ); 		
		} elseif (getenv('HTTP_CLIENT_IP')) {  			
			$ip_addr = getenv('HTTP_CLIENT_IP'); 		
		} else {  			
			$ip_addr = getenv('REMOTE_ADDR'); 		
		}	
	}
	return $ip_addr;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/117082-getip-function/#findComment-602182
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.