Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //SERP Check
- //By Erez.info
- //erezaton213@gmail.com
- //We will use UTF-8
- header('Content-Type: text/html; charset=utf-8');
- //How many pages???
- //WARNING: too many pages may block you.
- $max_pages = 4;
- //Sites array
- $info = array();
- $info[] = array(
- 'name' => 'ויקיפדיה',
- 'site' => 'he.wikipedia.org',
- 'keyword' => array('ישראל','ערים בישראל')
- );
- //Simple function to get the position.
- //Recive the site, keyword and start position.
- function check_position($site,$keyword,$start=0){
- //Set vars
- global $max_pages; //How many pages to check?
- $google = 'google.co.il'; //What google to check?
- //Recive the page HTML
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, 'http://www.'.$google.'/search?q='.urlencode($keyword).'&ie=utf-8&oe=utf-8&start='.$start);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_REFERER, 'http://www.google.com');
- curl_setopt($ch, CURLOPT_USERAGENT, 'Googlebot/2.1 (+http://www.google.com/bot.html)');
- $text = curl_exec($ch);
- curl_close($ch);
- //Find all the URLs on this page
- preg_match_all('/<a href="\/\/webcache.googleusercontent.com\/(.*)">עותק שמור<\/a>/U',$text,$sites);
- //Find match and return the location.
- foreach($sites[1] as $k=>$v){
- if(stristr(strip_tags($v),$site)){
- return (($k+1)+$start);
- }
- }
- //If not found go to the next page, or if this is the last page, then stop.
- if($start == (($max_pages-1)*10))return ($max_pages*10)+1;
- else return check_position($site,$keyword,($start+10));
- }
- function mysort($a,$b){
- if(is_array($a))$a = $a[0];
- if(is_array($b))$b = $b[0];
- if ($a == $b) {
- return 0;
- }
- return ($a < $b) ? -1 : 1;
- }
- echo '<html><head><title>דוח מיקומים</title></head><body dir="rtl">';
- echo '<h1>דוח מיקומים</h1>';
- //If there is a site to check
- if(isset($_GET['id']) && isset($info[$_GET['id']])){
- //Check if there is old check to compare to
- if(file_exists($_GET['id'].'.serp')){
- $pos2 = unserialize(file_get_contents($_GET['id'].'.serp'));
- }
- //New array with positions
- $pos = array();
- $v = $info[$_GET['id']];
- echo '<h2>'.$v['site'].'</h2>';
- $pages = array();
- //Start the loop!!!!!
- foreach($v['keyword'] as $k2=>$v2){
- //Get the position
- $pos[$v2] = check_position($v['site'],$v2);
- //Do we have an old check????
- if(isset($pos2[$v2])){
- //If equal, bigger, smaller and assign to array by the page number and the positin
- if($pos2[$v2] == $pos[$v2])$pages[ceil($pos[$v2]/10)][$v2] = $pos[$v2];
- elseif($pos2[$v2] < $pos[$v2])$pages[ceil($pos[$v2]/10)][$v2] = array($pos[$v2],$pos[$v2]-$pos2[$v2],'down');
- elseif($pos2[$v2] > $pos[$v2])$pages[ceil($pos[$v2]/10)][$v2] = array($pos[$v2],$pos2[$v2]-$pos[$v2],'up');
- } else{
- //If there is no old check just put it in the array
- $pages[ceil($pos[$v2]/10)][$v2] = $pos[$v2];
- }
- }
- //Sort the pages and LOOOOOOOOOOP
- ksort($pages);
- foreach($pages as $k=>$v){
- echo '<h3>עמוד '.(($k == $max_pages+1)?'???':$k).'</h3>';
- //Sort the array to recive ordered results
- uasort($v, "mysort");
- foreach($v as $k2=>$v2){
- //If it's array it means there is a compare value, but if it not then just print it.
- if(is_array($v2)){
- //If not found
- if($v2[0] == (($max_pages*10)+1))$v2[0] = '???';
- if($v2[2] == 'up')echo $k2.' - <strong style="color:green;">'.$v2[0].'</strong> עלייה של '.$v2[1].' מיקומים.';
- if($v2[2] == 'down')echo $k2.' - <strong style="color:red;">'.$v2[0].'</strong> ירידה של '.$v2[1].' מיקומים.';
- } else{
- if($v2 == (($max_pages*10)+1))$v2 = '???';
- echo $k2.' - <strong>'.$v2.'</strong>';
- }
- //Skip line
- echo '<br />';
- }
- }
- //Save the current position to file
- file_put_contents($_GET['id'].'.serp',serialize($pos));
- } elseif(isset($_GET['id'])){
- echo 'אין בכלל אתר באיידי הזה!!!!!!';
- } else{
- echo 'בחר אתר מהרשימה למטה.';
- }
- //Display the sites you added.
- echo '<div>'; foreach($info as $k=>$v)echo '<a href="?id='.$k.'">'.$v['name'].'</a> - '; echo '</div>';
- echo '</body></html>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement