userAgent)) { $this->userAgent = $_SERVER['HTTP_USER_AGENT']; } } /** * Check if the device is mobile. * * @return bool True if it's a mobile device, false otherwise. */ public function isMobile() { return $this->isDevice('mobile'); } /** * Check if the device is a tablet. * * @return bool True if it's a tablet, false otherwise. */ public function isTablet() { return $this->isDevice('tablet'); } /** * Check if the device is a phone. * * @return bool True if it's a phone, false otherwise. */ public function isPhone() { return $this->isDevice('phone'); } /** * Check if the device is of the specified type (mobile or tablet). * * @param string $type 'mobile' or 'tablet' * @return bool */ private function isDevice($type) { foreach ($this->mobileAgents as $agent) { if (stripos($this->userAgent, $agent) !== false) { return true; } } return false; } } ?>