-1

I found one script check index on google if site have indexed

function getPagesIndexedGoogle($site)
{
    if ($site) {
        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_HEADER => 0,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => "https://www.google.com.au/search?q=site:$site&gws_rd=ssl",
            CURLOPT_SSL_VERIFYPEER=> false,
            CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko'
        ));
        $result_string = curl_exec($curl);
        curl_close($curl);
        if (strpos($result_string, "did not match any documents") !== false) {
            return 0;
        } else {
            $match = preg_match("/about ([0-9,]{0,12})/i", $result_string, $matches);

            echo $matches[1];
        }
    }
}

if($_POST['domain']){
    $site = $_POST['domain'];
}
echo  $_POST['domain'] ;
echo getPagesIndexedGoogle($site);    

?>

How to check mutilple url?

I have used Foreach but it does not work. Please help me.

ekad
  • 14,436
  • 26
  • 44
  • 46
Steven
  • 3
  • 2
  • `$sites = array("site1","site2","site3"); foreach($sites as $site){ echo getPagesIndexedGoogle($site); }` - Replace array values with real websites of course. – icecub Sep 16 '16 at 01:46
  • goggle actively detects scrapers, expect that to be blocked, very quickly. –  Sep 16 '16 at 01:52
  • Thanks. I'm using Form let get Data.
    Domain :
    – Steven Sep 16 '16 at 01:56
  • Can you show me code let get Array ? – Steven Sep 16 '16 at 01:57
  • That will require a lot more work. You'll need to split the websites, check for valid input, etc etc. How are websites entered? Is each website on a new line or is there a space character between each of them? All in all you're asking for trouble. You don't control how users enter websites. – icecub Sep 16 '16 at 02:04

1 Answers1

0

As requested, this should do the trick:

<?php

function getPagesIndexedGoogle($site)
{
    if ($site) {
        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_HEADER => 0,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => "https://www.google.com.au/search?q=site:$site&amp;gws_rd=ssl",
            CURLOPT_SSL_VERIFYPEER=> false,
            CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko'
        ));
        $result_string = curl_exec($curl);
        curl_close($curl);
        if (strpos($result_string, "did not match any documents") !== false) {
            return 0;
        } else {
            $match = preg_match("/about ([0-9,]{0,12})/i", $result_string, $matches);

            echo $matches[1];
        }
    }
}

if(!empty($_POST['domain'])){

    // Tries to split URLs by new line or space character
    $sites = preg_split('#\\r\\n|\\r|\\n| #i', $_POST['domain']);

    foreach($sites as $site){
        // Checks if the URL is a valid website or not (http(s):// must be included!)
        if(preg_match('#((https?|ftp):\/\/(\S*?\.\S*?))([\s)\[\]{},;"\':<]|\.\s|$)#i', $site)){
            echo $site;
            echo getPagesIndexedGoogle($site);
        } else {
            echo $site;
            echo " is not a valid url.";
        }
    }

} else {
    echo "No websites were entered.";
}

?>

I still suggest you don't use a textarea but simple textfields instead. It's just less prone to errors.

icecub
  • 8,615
  • 6
  • 41
  • 70
  • Dear icecub, I used code of you but show error : unexpected '{' .I finded row if(preg_match but didn't look error. Please help me – Steven Sep 16 '16 at 02:53
  • @Steven It was a simple error. Fixed it. Code above should work now. – icecub Sep 16 '16 at 02:57
  • @Steven If my answer helped you out, please mark it as answered. This is a way of showing your appreciating to the one that helped you out and it will also make sure your question doesn't remain unanswered forever. – icecub Sep 16 '16 at 03:13
  • Yup, I was do it.Thanks again – Steven Sep 16 '16 at 03:14