在php中如何取得客户端(浏览网页的机器)的IP地址 $REMOTE_ADDR一般 PHP 的参考书里都会有 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用这个函数解决吧:<? function getIp() { $ip = getenv("REMOTE_ADDR"); $ip1 = getenv("HTTP_X_FORWARDED_FOR"); $ip2 = getenv("HTTP_CLIENT_IP"); ($ip1) ? $ip = $ip1 : null ; ($ip2) ? $ip = $ip2 : null ; return $ip; } ?> 下面的代码是从phpAdsNew里面copy出来的,看完之后对于获得proxy和client的ip有比较全面的认识// Check for proxyserver $proxy = false; if (isset ($GLOBALS['HTTP_VIA']) && $GLOBALS['HTTP_VIA'] != '') $proxy = true; if (isset ($GLOBALS['REMOTE_HOST'])) { if (is_int (strpos ('proxy', $GLOBALS['REMOTE_HOST']))) $proxy = true; if (is_int (strpos ('cache', $GLOBALS['REMOTE_HOST']))) $proxy = true; if (is_int (strpos ('inktomi', $GLOBALS['REMOTE_HOST']))) $proxy = true; } if ($proxy) { // Overwrite host address if a suitable header is found if (isset($GLOBALS['HTTP_FORWARDED']) && $GLOBALS['HTTP_FORWARDED'] != '') $IP = $GLOBALS['HTTP_FORWARDED']; if (isset($GLOBALS['HTTP_FORWARDED_FOR']) && $GLOBALS['HTTP_FORWARDED_FOR'] != '') $IP = $GLOBALS['HTTP_FORWARDED_FOR']; if (isset($GLOBALS['HTTP_X_FORWARDED']) && $GLOBALS['HTTP_X_FORWARDED'] != '') $IP = $GLOBALS['HTTP_X_FORWARDED']; if (isset($GLOBALS['HTTP_X_FORWARDED_FOR']) && $GLOBALS['HTTP_X_FORWARDED_FOR'] != '') $IP = $GLOBALS['HTTP_X_FORWARDED_FOR']; if (isset($GLOBALS['HTTP_CLIENT_IP']) && $GLOBALS['HTTP_CLIENT_IP'] != '') $IP = $GLOBALS['HTTP_CLIENT_IP']; // Get last item from list $IP = explode (',', $IP); $IP = trim($IP[count($IP) - 1]); if ($IP != 'unknown') { $GLOBALS['REMOTE_ADDR'] = $IP; $GLOBALS['REMOTE_HOST'] = ''; } } php长整形计算问题 MYSQL 表出问题Table 'XX' is marked as crashed and should be repaired mysql_fetch_row(): supplied argument is not a valid MySQL result resource 一个php文件中的undefined index怎么去除 函数定义问题 apache为什么会测试不成功出现错误 请问上传(WEB)的图片的问题 php中怎么对时间进行运算?? 一个初学的Mysql问题! 如何安装pear? 能否将一个表中的某一行的内容插入另一个表中 谁有好一点的国外代理???谢谢
<?
function getIp()
{
$ip = getenv("REMOTE_ADDR");
$ip1 = getenv("HTTP_X_FORWARDED_FOR");
$ip2 = getenv("HTTP_CLIENT_IP");
($ip1) ? $ip = $ip1 : null ;
($ip2) ? $ip = $ip2 : null ;
return $ip;
}
?>
// Check for proxyserver
$proxy = false; if (isset ($GLOBALS['HTTP_VIA']) && $GLOBALS['HTTP_VIA'] != '') $proxy = true; if (isset ($GLOBALS['REMOTE_HOST'])) { if (is_int (strpos ('proxy', $GLOBALS['REMOTE_HOST']))) $proxy = true; if (is_int (strpos ('cache', $GLOBALS['REMOTE_HOST']))) $proxy = true; if (is_int (strpos ('inktomi', $GLOBALS['REMOTE_HOST']))) $proxy = true; } if ($proxy) { // Overwrite host address if a suitable header is found if (isset($GLOBALS['HTTP_FORWARDED']) && $GLOBALS['HTTP_FORWARDED'] != '') $IP = $GLOBALS['HTTP_FORWARDED']; if (isset($GLOBALS['HTTP_FORWARDED_FOR']) && $GLOBALS['HTTP_FORWARDED_FOR'] != '') $IP = $GLOBALS['HTTP_FORWARDED_FOR']; if (isset($GLOBALS['HTTP_X_FORWARDED']) && $GLOBALS['HTTP_X_FORWARDED'] != '') $IP = $GLOBALS['HTTP_X_FORWARDED']; if (isset($GLOBALS['HTTP_X_FORWARDED_FOR']) && $GLOBALS['HTTP_X_FORWARDED_FOR'] != '') $IP = $GLOBALS['HTTP_X_FORWARDED_FOR']; if (isset($GLOBALS['HTTP_CLIENT_IP']) && $GLOBALS['HTTP_CLIENT_IP'] != '') $IP = $GLOBALS['HTTP_CLIENT_IP']; // Get last item from list $IP = explode (',', $IP); $IP = trim($IP[count($IP) - 1]); if ($IP != 'unknown') { $GLOBALS['REMOTE_ADDR'] = $IP; $GLOBALS['REMOTE_HOST'] = ''; } }