Skip to content

Commit

Permalink
🔨 BASE #212 new method
Browse files Browse the repository at this point in the history
  • Loading branch information
bjverde committed Dec 6, 2019
1 parent 28568c0 commit 521a85d
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions base/classes/helpers/ServerHelper.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@

class ServerHelper
{

const DEVICE_TYPE_MOBILE = 'MOBILE';
const DEVICE_TYPE_TABLE = 'TABLE';
const DEVICE_TYPE_DESKTOP = 'DESKTOP';

public static function get($atributeName)
{
if(!isset($_SERVER[$atributeName])) {
Expand All @@ -67,13 +72,14 @@ public static function getCurrentUrl( $trim_query_string = false )
$url = explode('?', $pageURL);
return $url[0];
}
}
}
/**
* Return string with IP client
* https://pt.stackoverflow.com/questions/179389/como-pegar-ip-de-um-usuario-usando-php/179455
*
* @return string
*/
public static function getIpClient()
public static function getClientIP()
{
$client = ArrayHelper::get($_SERVER,'HTTP_CLIENT_IP');
$forward = ArrayHelper::get($_SERVER,'HTTP_X_FORWARDED_FOR');
Expand All @@ -87,5 +93,21 @@ public static function getIpClient()
}
return $ip;
}

/**
* Return string with Device Type of client
* https://code-boxx.com/detect-mobile-desktop-in-php/
*
* @return string
*/
public static function getClientDeviceType()
{
if (is_numeric(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), self::DEVICE_TYPE_MOBILE))) {
return is_numeric(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), "tablet")) ? self::DEVICE_TYPE_TABLE : self::DEVICE_TYPE_DESKTOP ;
} else {
return 0;
}
}

}
?>

0 comments on commit 521a85d

Please sign in to comment.