[GH-ISSUE #21] Expand the get real ip function #18

Open
opened 2026-02-28 00:40:10 +03:00 by kerem · 2 comments
Owner

Originally created by @ghost on GitHub (May 1, 2014).
Original GitHub issue: https://github.com/telephone/LookingGlass/issues/21

Expand the Your IP Address with perhaps the following function

function getRealIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}

Originally created by @ghost on GitHub (May 1, 2014). Original GitHub issue: https://github.com/telephone/LookingGlass/issues/21 Expand the Your IP Address with perhaps the following function <code> function getRealIpAddr() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy { $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; } return $ip; } </code>
Author
Owner

@ldrrp commented on GitHub (Jan 23, 2015):

This one supports cloudflare too.

public function GET_IP(){ return getenv('HTTP_CLIENT_IP')?: getenv('HTTP_X_FORWARDED_FOR')?: getenv('HTTP_X_FORWARDED')?: getenv('HTTP_FORWARDED_FOR')?: getenv('HTTP_FORWARDED')?: getenv('REMOTE_ADDR')?: getenv('HTTP_CF_CONNECTING_IP')?: 'UNKNOWN'; }

<!-- gh-comment-id:71246162 --> @ldrrp commented on GitHub (Jan 23, 2015): This one supports cloudflare too. ` public function GET_IP(){ return getenv('HTTP_CLIENT_IP')?: getenv('HTTP_X_FORWARDED_FOR')?: getenv('HTTP_X_FORWARDED')?: getenv('HTTP_FORWARDED_FOR')?: getenv('HTTP_FORWARDED')?: getenv('REMOTE_ADDR')?: getenv('HTTP_CF_CONNECTING_IP')?: 'UNKNOWN'; } `
Author
Owner

@telephone commented on GitHub (Jan 26, 2015):

Leaving v1 as is for IP retrieval. This will be pushed to v2.

<!-- gh-comment-id:71422749 --> @telephone commented on GitHub (Jan 26, 2015): Leaving v1 as is for IP retrieval. This will be pushed to v2.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/LookingGlass#18
No description provided.