Code To Check if site is indexed in Google

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shanehunter
Forum Commoner
Posts: 30
Joined: Sun Jun 27, 2010 3:43 pm

Code To Check if site is indexed in Google

Post by shanehunter »

Hey Guys,

Does anybody out there have any code / ideas / examples of php code that will check if a website is indexed in google?
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Code To Check if site is indexed in Google

Post by Jade »

You might be able to find something here: http://www.google.com/webmasters/

Also I know there's a way you can upload your site map to google for indexing... just not sure I remember where I did it.
shanehunter
Forum Commoner
Posts: 30
Joined: Sun Jun 27, 2010 3:43 pm

Re: Code To Check if site is indexed in Google

Post by shanehunter »

Hi Jade,

Thanks for the quick return, but not exactly what I had in mind. =)

I need a php script that checks to see if a URL that is located in a text file is indexed in google (in google, you can just search "info:urlhere.com") then, if it is indexed, to move that url from the original text file into a new one. if it's not indexed, then it would move the url into an alternate text file.

make sense?
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Code To Check if site is indexed in Google

Post by Jade »

Ooh so you don't want to see which pages of the website are indexed, you just want to know if google has the site or not.
You'll need to be able to have allow_url_fopen turned on in your php.ini file. Then you need to do something like this:

Code: Select all

<?php

$url_list = array("whiteoakstables.net", "simdog.net", "bskgame.com", "horsega.me");
$found_index = array();
$missing_index = array();

foreach ($url_list => $item as $url)
{
    $googlesearch = "http://www.google.com/#hl=en&q=info%3A$url";
    $handle = fopen($googlesearch, "rb");
    $contents = stream_get_contents($handle);
 
    if (strpos($contents, "<cite>" . $url . "</cite>")) //or however you want to determine google has indexed this url
         array_push($found_index, $url);
    else
         array_push($missing_index, $url);
}

echo "Missing URLs:";
print_r($missing_index);
?>
Post Reply