Ec (2); obtain the user's IP address and determine the real IPfunctiongetIp () {& nbsp; if ($ _ SERVER [HTTP_CLIENT_IP]) & nbsp; & nbsp; {& nbsp; return $ _ SERVER [HTTP_CLIENT_IP]; & nbs script ec (2); script
Obtain the user IP address and determine the real IP Address
Function getIp (){
If ($ _ SERVER ['HTTP _ CLIENT_IP '])
{
Return $ _ SERVER ['HTTP _ CLIENT_IP '];
} Elseif ($ _ SERVER ['HTTP _ X_FORWARDED_FOR ']) {
Return $ _ SERVER ['HTTP _ X_FORWARDED_FOR '];
} Else {
Return $ _ SERVER ['remote _ ADDR '];
}
}
Function get_real_ip ()
{
$ Ip = false;
If (! Empty ($ _ SERVER ["HTTP_CLIENT_IP"])
{
$ Ip = $ _ SERVER ["HTTP_CLIENT_IP"];
}
If (! Empty ($ _ SERVER ['HTTP _ X_FORWARDED_FOR '])
{
$ Ips = explode (",", $ _ SERVER ['HTTP _ X_FORWARDED_FOR ']);
If ($ ip)
{
Array_unshift ($ ips, $ ip); $ ip = FALSE;
}
For ($ I = 0; $ I <count ($ ips); $ I ++)
{
If (! Eregi ("^ (10 | 172.16 | 192.168).", $ ips [$ I])
{
$ Ip = $ ips [$ I];
Break;
}
}
}
Return ($ ip? $ Ip: $ _ SERVER ['remote _ ADDR ']);
}