GDop Posted April 11, 2011 Share Posted April 11, 2011 Hello, I found some little php code to check google index of any site. <?php function checkSite($www) { $ch = curl_init('http://www.google.pl/search?hl=pl&q=site%3A'.trim($www).'&btnG=Szukaj&source=hp'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $sHtml = curl_exec($ch); preg_match('#\<div id=resultStats\>.*([0-9,]+) wynik#Ui', $sHtml, $aMatches); curl_close($ch); return (int)str_replace(',', '', $aMatches[1]); } echo checkSite('domain.com'); ?> But to check any site I must edit this code and add new site manually. I'm big beginner in PHP. I want to have a area on browser side to add many sites, and receive result, like in this code which I add. above. Can anybody help me with this? PS. Sorry for my poor English. Link to comment https://forums.phpfreaks.com/topic/233357-mass-check-google-site/ Share on other sites More sharing options...
drisate Posted April 11, 2011 Share Posted April 11, 2011 Something like this <?php function checkSite($www){ $ch = curl_init('http://www.google.pl/search?hl=pl&q=site%3A'.trim($www).'&btnG=Szukaj&source=hp'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $sHtml = curl_exec($ch); preg_match('#\<div id=resultStats\>.*([0-9,]+) wynik#Ui', $sHtml, $aMatches); curl_close($ch); return (int)str_replace(',', '', $aMatches[1]); } if ($_POST['www']){ echo checkSite($_POST['www']); }else{ print ('<form method="POST"><p>Check this site: http://www.<input type="text" name="www" size="20"><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p></form>'); } ?> Link to comment https://forums.phpfreaks.com/topic/233357-mass-check-google-site/#findComment-1200038 Share on other sites More sharing options...
GDop Posted April 11, 2011 Author Share Posted April 11, 2011 Thank You so much. It's almost this what I wanted But could You help me and do this with textarea (or something like that?), so when I add a few domains in new lines, eg: domain1.eu domain2.info domain3.com I will recive a result with indexed pages of all added domains, eg: 1222 (indexed pages in Google) 33223 (indexed pages in Google) 1233 (indexed pages in Google) I can't handle with this Link to comment https://forums.phpfreaks.com/topic/233357-mass-check-google-site/#findComment-1200071 Share on other sites More sharing options...
mattal999 Posted April 11, 2011 Share Posted April 11, 2011 <?php function checkSite($www) { $ch = curl_init('http://www.google.pl/search?hl=pl&q=site%3A'.trim($www).'&btnG=Szukaj&source=hp'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $sHtml = curl_exec($ch); preg_match('#\<div id=resultStats\>.*([0-9,]+) wynik#Ui', $sHtml, $aMatches); curl_close($ch); return (int)str_replace(',', '', $aMatches[1]); } if($_POST['www']) { $links = explode("\n", $_POST['www']); foreach($links as $link) { echo checkSite($_POST['www']) . "<br />"; } } else { print ('<form method="POST"><textarea name="www" rows="20" cols="100"></textarea><br /><br /><input type="submit" value="Submit" name="B1"> <input type="reset" value="Reset" name="B2"></form>'); } ?> Link to comment https://forums.phpfreaks.com/topic/233357-mass-check-google-site/#findComment-1200087 Share on other sites More sharing options...
GDop Posted April 11, 2011 Author Share Posted April 11, 2011 Thanks, @mattal999, but there is something wrong. It counts only domain from first line and shows the same result for rest of domains. Link to comment https://forums.phpfreaks.com/topic/233357-mass-check-google-site/#findComment-1200110 Share on other sites More sharing options...
mattal999 Posted April 11, 2011 Share Posted April 11, 2011 My bad - replace: foreach($links as $link) { echo checkSite($_POST['www']) . "<br />"; } With: foreach($links as $link) { echo checkSite($link) . "<br />"; } Link to comment https://forums.phpfreaks.com/topic/233357-mass-check-google-site/#findComment-1200132 Share on other sites More sharing options...
Adam Posted April 11, 2011 Share Posted April 11, 2011 I don't want to test the limits myself, but are you aware Google requests Captcha verification if you spam it? Being behind a proxy we sometimes get it at work.. Link to comment https://forums.phpfreaks.com/topic/233357-mass-check-google-site/#findComment-1200133 Share on other sites More sharing options...
GDop Posted April 11, 2011 Author Share Posted April 11, 2011 @mattal999 - Thank You so much, You're great. Thanks! @MrAdam - Yes, If you send too many requests to Google , you'll be must verify yourself by Captcha. But this script is only for my personal use and it's on server not on my localhost... Anyway, thanks for help ! Link to comment https://forums.phpfreaks.com/topic/233357-mass-check-google-site/#findComment-1200186 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.