Skip to content

Commit

Permalink
[#212] Implementada função que retorna o IP da máquina cliente
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Barbosa de Macedo Junior committed Dec 4, 2019
1 parent 795e068 commit 88678fd
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions base/classes/helpers/ServerHelper.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@

class ServerHelper
{
public static function get($atributeName)
public static function get($atributeName)
{
if(!isset($_SERVER[$atributeName])) {
$_SERVER[$atributeName]="";
}
return is_null($_SERVER[$atributeName])?"":trim($_SERVER[$atributeName]);
}

}

/**
* https://stackoverflow.com/questions/6768793/get-the-full-url-in-php
*
* @param boolean $trim_query_string
* @return string|mixed
*/
public static function getCurrentUrl( $trim_query_string = false )
public static function getCurrentUrl( $trim_query_string = false )
{
$pageURL = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? "https://" : "http://";
$pageURL = $pageURL.$_SERVER["SERVER_NAME"];
Expand All @@ -67,7 +67,25 @@ public static function getCurrentUrl( $trim_query_string = false )
$url = explode('?', $pageURL);
return $url[0];
}
}
/**
* https://pt.stackoverflow.com/questions/179389/como-pegar-ip-de-um-usuario-usando-php/179455
*
* @return string
*/
public static function getIpClient()
{
$client = ArrayHelper::get($_SERVER,'HTTP_CLIENT_IP');
$forward = ArrayHelper::get($_SERVER,'HTTP_X_FORWARDED_FOR');
$remote = ArrayHelper::get($_SERVER,'REMOTE_ADDR');
if ( filter_var($client, FILTER_VALIDATE_IP) ){
$ip = $client;
} elseif ( filter_var($forward, FILTER_VALIDATE_IP) ){
$ip = $forward;
} else {
$ip = $remote;
}
return $ip;
}

}
?>

1 comment on commit 88678fd

@bjverde
Copy link
Owner

@bjverde bjverde commented on 88678fd Dec 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@barbosa2305 correção by jose barbosa

Please sign in to comment.