public function Rack() { header('Content-Type: application/json; charset=utf-8'); date_default_timezone_set('America/Montreal'); $keys = array('REQUEST_METHOD', 'SCRIPT_NAME', 'PATH_INFO', 'SERVER_NAME', 'SERVER_PORT', 'HTTP_ACCEPT', 'HTTP_ACCEPT_LANGUAGE', 'HTTP_ACCEPT_CHARSET', 'HTTP_USER_AGENT', 'HTTP_REMOTE_ADDR'); $rack = array_intersect_key($_SERVER, array_fill_keys($keys, true)); ksort($rack); // Extract the headers from $_SERVER. $headers = array(); foreach ($_SERVER as $key => $value) { $key = strtoupper($key); if (strpos($key, 'X_') === 0 || strpos($key, 'HTTP_') === 0 || in_array($key, static::$specialHeaders)) { if ($key === 'HTTP_CONTENT_TYPE' || $key === 'HTTP_CONTENT_LENGTH') { continue; } $headers[$key] = $value; } } ksort($headers); $result = array('rack' => $rack, 'headers' => $headers, 'get' => $_GET, 'cookie' => $_COOKIE, 'mobile' => array('userAgentType' => userAgentType(), 'isMobile' => IsMobile())); echo json_encode($result); }
/** * Determine whether or not the site is in mobile mode. * * @param mixed $value Sets a new value for mobile. Pass one of the following: * - true: Force mobile. * - false: Force desktop. * - null: Reset and use the system determined mobile setting. * - not specified: Use the current setting or use the system determined mobile setting. * @return bool */ function isMobile($value = '') { if ($value === true || $value === false) { $type = $value ? 'mobile' : 'desktop'; userAgentType($type); } elseif ($value === null) { userAgentType(false); } $type = userAgentType(); // Check the config for an override. (ex. Consider tablets mobile) $type = c('Garden.Devices.' . ucfirst($type), $type); switch ($type) { case 'app': case 'mobile': $IsMobile = true; break; default: $IsMobile = false; break; } return $IsMobile; }