PHP 获取访问端的IP地址

<?php


	$ip_address=getIpAddress();

	echo "$ip_address<br>";


	function getIpAddress(){
	   //ip是否来自共享互联网
		if (!empty($_SERVER['HTTP_CLIENT_IP'])){
			$ip_address = $_SERVER['HTTP_CLIENT_IP'];
		}
	   //ip是否来自代理
		elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
			$ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
		}
	   //ip是否来自远程地址
		else{
			$ip_address = $_SERVER['REMOTE_ADDR'];
		}
		return $ip_address;
	}


?>

 

posted on 2022-11-08 07:35  小目标青年  阅读(59)  评论(0编辑  收藏  举报