Script to check how many pages from a site is indexed in

OK, this is part of what I’m doing to fix my old script (php pagerank checker and sh*t). I noticed that my indexed page checker and bot last access checker did not work anymore. It was because I’m not using API at all to get the data. Instead, I do ┬ásome simple scraping on search result page. (So, I’m not calling any Azure Datamarket API here)

Without more a do, this is the full PHP script code:

//helper function
function between($string, $start, $end)
    $string=" " . $string;
    $ini   =strpos($string, $start);

    if ($ini == 0)
        return "";

    $len=strpos($string, $end, $ini) - $ini;
    return substr($string, $ini, $len);

//another helper function
function file_get_contents_curl($url, $referer="", $ua="Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Ubuntu/10.04 Chromium/7.0.514.0 Chrome/7.0.514.0 Safari/534.7")
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //Set curl to return the data instead of printing it to the browser.
    if ($referer!="") {
        curl_setopt($ch, CURLOPT_REFERER, $referer);
    } else {
        curl_setopt($ch, CURLOPT_REFERER, $url);
    //curl_setopt($ch, CURLOPT_URL, $url);
    if ($ua!="") {
		curl_setopt($ch, CURLOPT_USERAGENT, $ua);
	} else {

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_close ($ch);

    return $data;

//this is the main function
function msn_indexed($uri, $badge = 0)
    $uri =trim(str_ireplace('http://', '', $uri));
    $uri =trim(str_ireplace('http', '', $uri));
    $url ='' .urlencode( $uri).'&go=&qs=n&sk=&form=QBLH&mkt=en-WW';
    if (strpos($data, 'sb_count')!==FALSE) {
	return (integer)str_replace(",", "", trim(between($data, '', 'result')));
    } else {
	return 0;

No fancy and advanced code there, just simple cut and grab. You might consider using regex when parsing the search results from

How to use it


The result would be in integer (0 if hasn’t indexed any of your site’s pages).

Fully working demo can be seen here: on “ Indexed” part.

bing indexed page in search result

this is how you check how many your site’s pages are indexed by

As you can see that the result may vary depending on your location (or where you put the script) and sometimes, gave invalid result (such as 0, where the real value might be higher than that)

  1. Nice script
    Thank you..

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Trackbacks and Pingbacks: