Switching code – PHP


'none');

if (DA_USE_COOKIES && isset($_COOKIE['Mobi_Mtld_DA_Properties'])) {
$da_results = (array)json_decode($_COOKIE['Mobi_Mtld_DA_Properties'], true);
$da_results['_source'] = 'cookie';
}
if (DA_USE_CACHE && $da_results['_source'] === 'none') {
$da_cache_file = md5($_SERVER["HTTP_USER_AGENT"]) . '.json';
if (!file_exists(DA_CACHE_DIR) && !@mkdir(DA_CACHE_DIR)) {
$da_results['_error'] = "Unable to create cache directory: " . DA_CACHE_DIR . "\n";
} else {
$da_json = @file_get_contents(DA_CACHE_DIR . $da_cache_file);
if ($da_json !== false) {
$da_results = (array)json_decode($da_json, true);
$da_results['_source'] = 'cache';
if (DA_USE_COOKIES) {
setcookie('Mobi_Mtld_DA_Properties', $da_json);
}
}
}
}
if ($da_results['_source'] === 'none') {
$da_json = @file_get_contents(DA_URI . "?User-Agent=" . urlencode($_SERVER["HTTP_USER_AGENT"]));
if ($da_json !== false) {
$da_results = array_merge(json_decode($da_json, true), $da_results);
$da_results['_source'] = 'webservice';
if (DA_USE_COOKIES) {
setcookie('Mobi_Mtld_DA_Properties', $da_json);
}
if (DA_USE_CACHE) {
if (@file_put_contents(DA_CACHE_DIR . $da_cache_file, $da_json) === false) {
$da_results['_error'] .= "Unable to write cache file " . DA_CACHE_DIR . $da_cache_file . "\n";
}
}
} else {
$da_results['_error'] .= "Error fetching DeviceAtlas data from webservice.\n";
}
}

if($da_results['mobileDevice']) header('Location: ' . MOBILE_SITE);
else header('Location: ' . DESKTOP_SITE);

?>

Other Products

Market leading device intelligence for the web, app and MNO ecosystems
DeviceAtlas - Device Intelligence

Real-time identification of fraudulent and misrepresented traffic
DeviceAssure - Device Verification

A free tool for developers, designers and marketers to test website performance
mobiReady - Evaluate your websites’ mobile readiness

© 2024 DeviceAtlas Limited. All rights reserved.

This is a website of DeviceAtlas Limited, a private company limited by shares, incorporated and registered in the Republic of Ireland with registered number 398040 and registered office at 6th Floor, 2 Grand Canal Square, Dublin 2, Ireland