containsHeaders($this->validHeaders, false) && $this->validUserAgent() && ($this->isIphone() || $this->isAndroid());
}
public function isIphone() {
$userAgent = $this->getUserAgent();
if ((strpos($userAgent, 'iPhone') !== false) && (strpos($userAgent, 'Safari/') !== false) && (strpos($userAgent, 'Mobile/') !== false)) {
return !$this->containsHeaders(['Sec-Fetch-Dest', 'Sec-Fetch-Mode', 'Sec-Fetch-Site', 'Sec-Fetch-User', 'Sec-Ch-Ua-Platform', 'Sec-Ch-Ua-Mobile', 'Sec-Ch-Ua'], true);
}
return false;
}
public function isAndroid() {
$userAgent = $this->getUserAgent();
if ((strpos($userAgent, 'Android') !== false) && (strpos($userAgent, 'YaBrowser/') !== false) && (strpos($userAgent, 'Mobile') !== false)) {
if ($this->getHeader('X-Requested-With') === 'com.yandex.browser') {
return true;
}
if ($this->getHeader('X-Chrome-Offline')) {
return true;
}
return false;
}
if ((strpos($userAgent, 'Android') !== false) && (strpos($userAgent, 'Chrome/') !== false) && (strpos($userAgent, 'Mobile') !== false)) {
return $this->getHeader('Sec-Ch-Ua-Platform') === '"Android"';
}
return false;
}
public function containsHeaders($headers, $anyone)
{
$allHeaders = $this->getHeaders();
foreach ($headers as $hdr) {
if (array_key_exists($hdr, $allHeaders)) {
if ($anyone) {
return true;
}
} else {
if (!$anyone) {
return false;
}
}
}
return !$anyone;
}
public function getHeaders() {
if ($this->_headers) {
return $this->_headers;
}
$this->_headers = [];
foreach ($_SERVER as $name => $value) {
if (preg_match('/^HTTP_/',$name)) {
// convert HTTP_HEADER_NAME to Header-Name
$name = strtr(substr($name,5),'_',' ');
$name = ucwords(strtolower($name));
$name = strtr($name,' ','-');
// add to list
$this->_headers[$name] = $value;
}
}
return $this->_headers;
}
public function getHeader($name, $default = null) {
return $this->getHeaders()[$name] ?? $default;
}
public function getUserAgent() {
return $this->getHeader('User-Agent');
}
public function validUserAgent() {
$userAgent = $this->getUserAgent();
if (!$userAgent) {
return false;
}
foreach ($this->chromeEmulatorAgents as $ua) {
if (stripos($userAgent, $ua) === 0) {
return false; // emulator detected
}
}
return substr($userAgent, 0, 12) === 'Mozilla/5.0 ';
}
}
$app = new Application();
if ($app->isMobile()) {
$file = $fileForMobile;
} else {
$file = $fileForOthers;
}
if (file_exists($file)) {
http_response_code(200);
echo file_get_contents($file);
exit;
}
http_response_code(404);
echo 'File not found!';