Guest User

Erez

a guest
Apr 18th, 2012
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.22 KB | None | 0 0
  1. <?php
  2.     //SERP Check
  3.     //By Erez.info
  4.  
  5.     //We will use UTF-8
  6.     header('Content-Type: text/html; charset=utf-8');
  7.     //How many pages???
  8.     //WARNING: too many pages may block you.
  9.     $max_pages = 4;
  10.    
  11.     //Sites array
  12.     $info = array();
  13.     $info[] = array(
  14.         'name' => 'ויקיפדיה',
  15.         'site' => 'he.wikipedia.org',
  16.         'keyword' => array('ישראל','ערים בישראל')
  17.         );
  18.    
  19.     //Simple function to get the position.
  20.     //Recive the site, keyword and start position.
  21.     function check_position($site,$keyword,$start=0){
  22.         //Set vars
  23.         global $max_pages; //How many pages to check?
  24.         $google = 'google.co.il'; //What google to check?
  25.        
  26.         //Recive the page HTML
  27.         $ch = curl_init();
  28.         curl_setopt($ch, CURLOPT_URL, 'http://www.'.$google.'/search?q='.urlencode($keyword).'&ie=utf-8&oe=utf-8&start='.$start);
  29.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  30.         curl_setopt($ch, CURLOPT_REFERER, 'http://www.google.com');
  31.         curl_setopt($ch, CURLOPT_USERAGENT, 'Googlebot/2.1 (+http://www.google.com/bot.html)');
  32.         $text = curl_exec($ch);
  33.         curl_close($ch);
  34.        
  35.         //Find all the URLs on this page
  36.         preg_match_all('/<a href="\/\/webcache.googleusercontent.com\/(.*)">עותק שמור<\/a>/U',$text,$sites);
  37.        
  38.         //Find match and return the location.
  39.         foreach($sites[1] as $k=>$v){
  40.             if(stristr(strip_tags($v),$site)){
  41.                 return (($k+1)+$start);
  42.             }
  43.         }
  44.        
  45.         //If not found go to the next page, or if this is the last page, then stop.
  46.         if($start == (($max_pages-1)*10))return ($max_pages*10)+1;
  47.         else return check_position($site,$keyword,($start+10));
  48.        
  49.     }
  50.    
  51.     function mysort($a,$b){
  52.         if(is_array($a))$a = $a[0];
  53.         if(is_array($b))$b = $b[0];
  54.         if ($a == $b) {
  55.             return 0;
  56.         }
  57.         return ($a < $b) ? -1 : 1;
  58.     }
  59.    
  60.     echo '<html><head><title>דוח מיקומים</title></head><body dir="rtl">';
  61.     echo '<h1>דוח מיקומים</h1>';
  62.    
  63.     //If there is a site to check
  64.     if(isset($_GET['id']) && isset($info[$_GET['id']])){
  65.         //Check if there is old check to compare to
  66.         if(file_exists($_GET['id'].'.serp')){
  67.             $pos2 = unserialize(file_get_contents($_GET['id'].'.serp'));
  68.         }
  69.        
  70.         //New array with positions
  71.         $pos = array();
  72.         $v = $info[$_GET['id']];
  73.         echo '<h2>'.$v['site'].'</h2>';
  74.         $pages = array();
  75.         //Start the loop!!!!!
  76.         foreach($v['keyword'] as $k2=>$v2){
  77.             //Get the position
  78.             $pos[$v2] = check_position($v['site'],$v2);
  79.             //Do we have an old check????
  80.             if(isset($pos2[$v2])){
  81.                 //If equal, bigger, smaller and assign to array by the page number and the positin
  82.                 if($pos2[$v2] == $pos[$v2])$pages[ceil($pos[$v2]/10)][$v2] = $pos[$v2];
  83.                 elseif($pos2[$v2] < $pos[$v2])$pages[ceil($pos[$v2]/10)][$v2] = array($pos[$v2],$pos[$v2]-$pos2[$v2],'down');
  84.                 elseif($pos2[$v2] > $pos[$v2])$pages[ceil($pos[$v2]/10)][$v2] = array($pos[$v2],$pos2[$v2]-$pos[$v2],'up');
  85.             } else{
  86.                 //If there is no old check just put it in the array
  87.                 $pages[ceil($pos[$v2]/10)][$v2] = $pos[$v2];
  88.             }
  89.         }
  90.         //Sort the pages and LOOOOOOOOOOP
  91.         ksort($pages);
  92.         foreach($pages as $k=>$v){
  93.             echo '<h3>עמוד '.(($k == $max_pages+1)?'???':$k).'</h3>';
  94.             //Sort the array to recive ordered results
  95.             uasort($v, "mysort");
  96.             foreach($v as $k2=>$v2){
  97.                 //If it's array it means there is a compare value, but if it not then just print it.
  98.                 if(is_array($v2)){
  99.                     //If not found
  100.                     if($v2[0] == (($max_pages*10)+1))$v2[0] = '???';
  101.                    
  102.                     if($v2[2] == 'up')echo $k2.' - <strong style="color:green;">'.$v2[0].'</strong> עלייה של '.$v2[1].' מיקומים.';
  103.                     if($v2[2] == 'down')echo $k2.' - <strong style="color:red;">'.$v2[0].'</strong> ירידה של '.$v2[1].' מיקומים.';
  104.                 } else{
  105.                     if($v2 == (($max_pages*10)+1))$v2 = '???';
  106.                    
  107.                     echo $k2.' - <strong>'.$v2.'</strong>';
  108.                 }
  109.                 //Skip line
  110.                 echo '<br />';
  111.             }
  112.         }
  113.        
  114.         //Save the current position to file
  115.         file_put_contents($_GET['id'].'.serp',serialize($pos));
  116.     } elseif(isset($_GET['id'])){
  117.         echo 'אין בכלל אתר באיידי הזה!!!!!!';
  118.     } else{
  119.         echo 'בחר אתר מהרשימה למטה.';
  120.     }
  121.    
  122.     //Display the sites you added.
  123.     echo '<div>'; foreach($info as $k=>$v)echo '<a href="?id='.$k.'">'.$v['name'].'</a> - '; echo '</div>';
  124.     echo '</body></html>';
Advertisement
Add Comment
Please, Sign In to add comment