Function real_ip ()
{
Static $ realip = NULL;
If ($ realip! = NULL)
{
Return $ realip;
}
If (isset ($ _ SERVER ))
{
If (isset ($ _ SERVER ['HTTP _ X_FORWARDED_FOR '])
{
$ Arr = explode (',', $ _ SERVER ['HTTP _ X_FORWARDED_FOR ']);
Foreach ($ arr AS $ ip)
{
$ Ip = trim ($ ip );
If ($ ip! = 'Unknown ')
{
$ Realip = $ ip;
Break;
}
}
}
Elseif (isset ($ _ SERVER ['HTTP _ CLIENT_IP '])
{
$ Realip = $ _ SERVER ['HTTP _ CLIENT_IP '];
}
Else
{
If (isset ($ _ SERVER ['remote _ ADDR '])
{
$ Realip = $ _ SERVER ['remote _ ADDR '];
}
Else
{
$ Realip = '0. 0.0.0 ';
}
}
}
Else
{
If (getenv ('HTTP _ X_FORWARDED_FOR '))
{
$ Realip = getenv ('HTTP _ X_FORWARDED_FOR ');
}
Elseif (getenv ('HTTP _ CLIENT_IP '))
{
$ Realip = getenv ('HTTP _ CLIENT_IP ');
}
Else
{
$ Realip = getenv ('remote _ ADDR ');
}
}
Preg_match ("/[\ d \.] {7, 15}/", $ realip, $ onlineip );
$ Realip =! Empty ($ onlineip [0])? $ Onlineip [0]: '0. 0.0.0 ';
Return $ realip;
}
Author: huangcun tingyu 31