url as $url) {
$urls[] = (string) $url->loc;
}
return $urls;
}
// Get all URLs from the sitemap
$urls = getSitemapUrls($sitemapUrl);
// Prepare the payload for IndexNow
$data = [
"host" => parse_url($sitemapUrl, PHP_URL_HOST),
"key" => $apiKey,
"keyLocation" => "https://pathoworld.in/$apiKey.txt", // Optional key file
"urlList" => $urls
];
$jsonData = json_encode($data);
// Send POST request to Bing
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.bing.com/indexnow");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Show response
if ($httpCode == 200) {
echo "✅ Sitemap submitted successfully! Bing is indexing your pages.
";
} else {
echo "❌ Submission failed. HTTP Code: $httpCode
";
echo "$response
";
}
?>