[PHP Script] Website Ranking Check

Discussion in 'Products & Tools' started by mai4809, Oct 15, 2009.

  1. #1
    I just migrate from my old forum to digital point because I see many better tricks for SEO. Anyway I'm a new member, I don't know where to start so I would like to giving you the script that I always use to track my keyword ranking.

    <?php
    
    if (isset($_GET['search'])){
        $q = '';
        foreach($_GET as $k=>$v){
          $q.='&'.urlencode($k).'='.urlencode($v);
        }
        header('Content-type:text/xml;charset=tis-620');
        $s = file_get_contents('http://www.google.com/search?'.$q);
    
        function cite_callback($m){
          global $cites;
          list($c)=explode(' - ',strip_tags($m[1]));
          $c=preg_replace('/\s+/','',$c);
          $cites.="<c>{$c}</c>";
          return '';
        }
        $s = strstr($s,'<ol>');
        $s = substr($s,0,strpos($s,'</ol>')+5);
        $cites = '';
        preg_replace_callback('/<cite>(.+?)<\/cite>/','cite_callback',$s);
        echo '<?xml version="1.0" encoding="tis-620" ?>'.
                "<google>{$cites}</google>";
        exit();
    }
    
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="th" xml:lang="th">
    <head>
        <title>google order check tool</title>
      <meta http-equiv="Content-Type" content="text/html; charset=tis-620" />
      <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
      <script type="text/javascript">
      /*<![CDATA[*/
      var gTimer;
      var gProgress;
      function progress(){
        if (gProgress){
            gProgress.val(gProgress.val()*1+1);
        }
          gTimer = setTimeout('progress()',1000);
      }
      function clearProgress(){
            gProgress.val(0);
            if (gTimer)    clearTimeout(gTimer);
      }
      $(document).ready(function(){
            var website = $('#website');
            var num = $('#num');
            var keyword = $('#keyword');
            var order = $('#order');
            var result = $('#result');
        gProgress = $('#progress');
    
            $('#searchForm').submit(function(e){
                var meta = $('input[name=meta]:checked');
                var data;
                if (meta.val()=='')
                    data = {
                             as_q: keyword.val(),
                            num: num.val(),
                            oe: 'tis-620'
                    };
                else
                    data = {
                        hl: 'th',
                             q: keyword.val(),
                             as_qdr: 'all',
                            num: num.val(),
                            meta: meta.val(),
                            oe: 'tis-620'
                    };
                $.ajax({
                 dataType: 'xml',
                 type: "GET",
                 url: "?search",
                 data: data,
                 beforeSend: function() {
                        clearProgress();
                        progress();
                        order.html('');
                        result.html('');
                 },
                 success: function(google) {
                   var strOrder='';
                   var strResult='';
                   $('c',google).each(function(n){
                            var site = $(this).text();
                            n++;
                        if (site.indexOf(website.val()) == -1) {
                          strResult += n+': '+site+'<br />';
                            } else {
                              strOrder += website.val()+' Rank is '+n+
                                    ' with keyword \''+keyword.val()+'\'<br />';
                              strResult += n+': <span style="color:red;">'+site+'</span><br />';
                            }
                     });
                   clearProgress();
                     result.hide();
                     if (strOrder=='') {
                      order.html('No result found in '+num.val()+' ');
                     }else{
                      order.html(strOrder);
                     }
                     if (strResult=='') {
                      result.html('No result for this keyword').show('normal');
                     }else{
                      result.html(strResult).show('normal');
                     }
                 },
                 error: function(a,b,c){
                  alert(b);
                 }
                });
                return false;
            });
      });
      /*]]>*/
      </script>
    </head>
    <body>
    
    <b>Rabking Check</b>
    <br />
    
    <div><form action="?" id="searchForm">
      website: <input type="text" id="website" /><br />
        keyword: <input type="text" id="keyword" /><br />
        result: <select id="num">
          <option value="5">5</option>
          <option value="10" selected="selected">10</option>
          <option value="20">20</option>
            <option value="50">50</option>
            <option value="100">100</option>
            </select>
        <br />
        Search :
            <input type="radio" name="meta" value="" checked="checked" />Web
        <br />
        progress: <input type="text" id="progress" /><br />
        <input type="submit" id="request" value="search" />
    </form></div>
    
    <div style="background-color:yellow">
        Rank: <br /><span id="order"></span>
    </div>
    <div style="background-color:lightyellow">
        Result : <span id="result"></span>
    </div>
    
    </body>
    </html>
    PHP:

     
    Last edited: Oct 15, 2009
    mai4809, Oct 15, 2009 IP
  2. dexaffiliate

    dexaffiliate Peon

    Messages:
    66
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It looks really nice! Thank you for sharing!
     
    dexaffiliate, Oct 15, 2009 IP
  3. saber123

    saber123 Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    yes i want to try this now,thanks a lot for your sharing^^
     
    saber123, Oct 15, 2009 IP
  4. dburdon

    dburdon Peon

    Messages:
    485
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Mai4809,

    how does this script compare with the tracking code from Digital Point?
     
    dburdon, Oct 15, 2009 IP
  5. mai4809

    mai4809 Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Oops, sorry for who those already try out the script and it not working. I have already fix it just copy the code again in the 1st post and try.

    Demo:

    http://ugetblog.com/seo/ranking.php
    Code (markup):
     
    mai4809, Oct 15, 2009 IP
  6. dburdon

    dburdon Peon

    Messages:
    485
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Mai,

    am I right in thinking the results refer to Google.co.th. That is Thailand?
     
    dburdon, Oct 15, 2009 IP
  7. mai4809

    mai4809 Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yes sir, I'm Thai

    You can change to Google.com if you want to just open the file and replace all google.co.th with google.com
     
    mai4809, Oct 15, 2009 IP
  8. dburdon

    dburdon Peon

    Messages:
    485
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Mai4809,

    I've tried replacing google.co.th with both google.com and google.co.uk without success. Is it something to do with the Javascript file featured near the top of the page?
     
    dburdon, Oct 15, 2009 IP
  9. mai4809

    mai4809 Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Can you copy the code above again and try ( I have change to google.com ) and I work fine for me.

    If not please tell me, what is yours PHP version and the problem
     
    Last edited: Oct 15, 2009
    mai4809, Oct 15, 2009 IP
  10. dburdon

    dburdon Peon

    Messages:
    485
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Mai4809,

    I ran the script on another server and it works fine.

    Many thanks, David Burdon
     
    dburdon, Oct 15, 2009 IP
  11. dexaffiliate

    dexaffiliate Peon

    Messages:
    66
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Yes I tested it too and works perfect!! Thank you again!
     
    dexaffiliate, Oct 15, 2009 IP
  12. Jontish

    Jontish Well-Known Member

    Messages:
    1,565
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    128
    #12
    Oo, nice job. Thanks!
     
    Jontish, Oct 20, 2009 IP
  13. farishussain

    farishussain Peon

    Messages:
    81
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Works perfect .. thanks for sharing please share some scripts like webmaster tools
     
    farishussain, Oct 20, 2009 IP
  14. mai4809

    mai4809 Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    I have one script that use to check lastest bot that visited our sites, maybe i will share that for you guy when i get back home XD
     
    mai4809, Oct 20, 2009 IP
  15. rajput_jitendra

    rajput_jitendra Peon

    Messages:
    69
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Thank you for sharing above script with us it's really work for me.
     
    rajput_jitendra, Nov 2, 2009 IP