Check if it is Localhost or server:
function is_localhost()
{
$whitelist = array( '127.0.0.1', '::1' );
return in_array( $_SERVER['REMOTE_ADDR'], $whitelist);
}
just call the function LIke,
$isLocalhost = is_localhost();
echo $isLocalhost;