Advertisement
Guest User

Erez

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