Check if URL is indexed by Google using PHP

前端 未结 4 1908
太阳男子
太阳男子 2021-01-18 18:24

I would like to know if it\'s possible to check if URL is indexed by Google using PHP.

Is this against their ToS?

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-18 19:00

    To do so without an API is against the TOS. For low volume, you can:

    // CHECK IF PAGE IS IN GOOGLE INDEX
    $domain = 'stackexchange.com';
    if (strstr(file_get_contents("http://www.google.com/search?q=site:$domain"), 'did not match any documents')) {
      // Page is not in the index
      print 'No Go!';
    }
    else {
      print 'All Good!';
    }
    exit;
    

提交回复
热议问题