Skip to content

Instantly share code, notes, and snippets.

@rseon
Created June 21, 2019 08:29
Show Gist options
  • Save rseon/6f79b1dd81aa8e3ca0186ff38a7824e3 to your computer and use it in GitHub Desktop.
Save rseon/6f79b1dd81aa8e3ca0186ff38a7824e3 to your computer and use it in GitHub Desktop.
How to get client IP address in PHP
<?php
// @link http://itman.in/en/how-to-get-client-ip-address-in-php/
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment