<?php
//在common/function 里面加入下函数
function GetIP()
{
if(!empty($_SERVER["HTTP_CLIENT_IP"]))
$cip = $_SERVER["HTTP_CLIENT_IP"];
else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"]))
$cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
else if(!empty($_SERVER["REMOTE_ADDR"]))
$cip = $_SERVER["REMOTE_ADDR"];
else
$cip = "无法获取!";
return $cip;
}
//在类里面直接调用就行了
public function test()
{
$data = I('test_data');
$ip = GetIP();
echo $ip;//实时ip
}
?>