lang/php

IP 주소확인

C/H 2012. 6. 12. 17:37

참고 :  웹 서버 접속자의 IP 주소확인 


  • REMOTE_ADDR
  • HTTP_X_FORWARDED_FOR
    방화벽 + 사설 아이피
  • HTTP_CLIENT_IP
    방화벽 + 공인아이피
  1. REMOTE_ADDR/HTTP_X_FORWARDED_FOR
  2. REMOTE_ADDR/HTTP_CLIENT_IP
  3. REMOTE

PHP로 변환

/**
 * get ip address
 * 
 * @package	common
 * @version	2012-06-12
 * @author	xCode
 * @param	Boolean	$inet=false
 * @return	String
 */
function getAddr($inet=false){
	$addr = $_SERVER['REMOTE_ADDR'];
	if( isset($_SERVER['HTTP_X_FORWARDED_FOR']) ) $addr .=  "/".$_SERVER['HTTP_X_FORWARDED_FOR'];
	else if( isset($_SERVER['HTTP_CLIENT_IP']) ) $addr .= "/".$_SERVER['HTTP_CLIENT_IP'];

	if( $inet ){
		$tmp = explode("/", $addr);
		$addr = ip2long($tmp[0]);
		if( isset($tmp[1]) ) $addr .= ".".ip2long($tmp[1]);
	}
	return $addr;
}


반응형