Belirli bir anahtar kelime için bir web sitesinin Google'daki konumunu kontrol etmek için basit bir PHP betiği:
<?php
function checkKeywordPosition($keyword, $websiteUrl) {
$googleUrl = "http://www.google.com/search?q=" . urlencode($keyword) . "&num=100";
$page = file_get_contents($googleUrl);
// Check if the page was fetched successfully
if ($page === FALSE) {
return "Error: Unable to fetch Google search results.";
}
// Find the position of the website in search results
$position = strpos($page, $websiteUrl);
// If the website is found, return its position
if ($position !== FALSE) {
// Google starts indexing from 1 instead of 0
return "The website is found at position " . ($position + 1);
} else {
return "The website is not found in the top 100 results.";
}
}
// Example usage
$keyword = "your keyword here";
$websiteUrl = "your website URL here";
$result = checkKeywordPosition($keyword, $websiteUrl);
echo $result;
?>
Bu komut dosyası, giriş parametreleri olarak bir anahtar kelimeyi ve web sitesi URL'sini alır, bu anahtar kelimeye ilişkin Google arama sonuçlarını getirir ve ardından verilen web sitesi URL'sinin bu arama sonuçlarındaki konumunu kontrol eder. Web sitesi bulunursa konumu veya web sitesinin ilk 100 sonuç arasında bulunmadığını belirten bir mesaj döndürür. Bu komut dosyasının, güvenlik kısıtlamaları veya ağ yapılandırmaları nedeniyle tüm ortamlarda çalışmayabilecek basit dosya alma yöntemlerini kullandığını unutmayın. Ayrıca, arama motoru sonuçlarının kazınması hizmet şartlarını ihlal edebilir; bu nedenle, bunu sorumlu bir şekilde kullanın ve bu tür amaçlar için arama motorları tarafından sağlanan API'leri kullanmayı düşünün.
Yorumlar (0)
Burada henüz yorum yok, ilk siz olabilirsiniz!