Skip to content

Commit

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

const DEVICE_TYPE_MOBILE = 'MOBILE';
const DEVICE_TYPE_TABLE = 'TABLE';
const DEVICE_TYPE_DESKTOP = 'DESKTOP';
const DEVICE_TYPE_MOBILE = 'mobile';
const DEVICE_TYPE_TABLE = 'tablet';
const DEVICE_TYPE_DESKTOP = 'desktop';

public static function get($atributeName)
{
Expand Down Expand Up @@ -94,6 +94,11 @@ public static function getClientIP()
return $ip;
}

public static function getClientAgent(){
$agent = ArrayHelper::get($_SERVER,'HTTP_USER_AGENT');
return $agent;
}

/**
* Return string with Device Type of client
* https://code-boxx.com/detect-mobile-desktop-in-php/
Expand All @@ -102,11 +107,16 @@ public static function getClientIP()
*/
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;
$agent = strtolower(self::getClientAgent());
$type = null;
if (is_numeric(strpos($agent, self::DEVICE_TYPE_MOBILE))) {
$type = self::DEVICE_TYPE_MOBILE;
} else if( is_numeric(strpos($agent, self::DEVICE_TYPE_TABLE)) ) {
$type = self::DEVICE_TYPE_TABLE;
}else{
$type = self::DEVICE_TYPE_DESKTOP;
}
return $type;
}

}
Expand Down

0 comments on commit 2657303

Please sign in to comment.