SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 28
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2011
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Input fields that refuses user to submit website with a lower pagerank than X

    Hey
    I need to recode my directory input submission field URL to not let the user submit his website if the user's website has a lower pagerank than 2.
    Any ides how to do this, i am thinking that jquery would be the easiest way.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,683
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by imediazone View Post
    Hey
    I need to recode my directory input submission field URL to not let the user submit his website if the user's website has a lower pagerank than 2.
    Any ides how to do this, i am thinking that jquery would be the easiest way.
    The following SEOStats can be used from PHP in order to allow you to retrieve info such as the pagerank of a domain. You could then from JavaScript use an AJAX request to your PHP script to retrieve the information that you're needing.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2011
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    The following SEOStats can be used from PHP in order to allow you to retrieve info such as the pagerank of a domain. You could then from JavaScript use an AJAX request to your PHP script to retrieve the information that you're needing.
    Thanks for the response Paul, just that i am kind of a noob in programming, could you please give a bit more details.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,683
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by imediazone View Post
    Thanks for the response Paul, just that i am kind of a noob in programming, could you please give a bit more details.
    If you want help with the PHP side of things, which is what you will be needing to retrieve and process the pagerank information, I suggest that you contact the good people at the PHP forum for assistance with that.

    JavaScript is not capable of doing that work for you, but it can retrieve the information that you need from a PHP script that you would create for this task.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Zealot
    Join Date
    Jan 2011
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    If you want help with the PHP side of things, which is what you will be needing to retrieve and process the pagerank information, I suggest that you contact the good people at the PHP forum for assistance with that.

    JavaScript is not capable of doing that work for you, but it can retrieve the information that you need from a PHP script that you would create for this task.
    Just noticed, i have the PHP that gets the pagerank, located in a folder components/googlepageranker.php. This is the code inside it.
    <?php

    class GooglePageRanker {

    function StrToNum($Str, $Check, $Magic)
    {
    $Int32Unit = 4294967296; // 2^32
    $length = strlen($Str);
    for ($i = 0; $i < $length; $i++) {
    $Check *= $Magic;
    /* If the float is beyond the boundaries of integer (usually +/- 2.15e+9 = 2^31),
    the result of converting to integer is undefined
    refer to http://www.php.net/manual/en/language.types.integer.php */
    if ($Check >= $Int32Unit) {
    $Check = ($Check - $Int32Unit * (int) ($Check / $Int32Unit));
    //if the check less than -2^31
    $Check = ($Check < -2147483648) ? ($Check + $Int32Unit) : $Check;
    }
    $Check += ord($Str{$i});
    }
    return $Check;
    }

    // Generate a proper hash for an url
    function HashURL($String)
    {
    $Check1 = $this->StrToNum($String, 0x1505, 0x21);
    $Check2 = $this->StrToNum($String, 0, 0x1003F);

    $Check1 >>= 2;
    $Check1 = (($Check1 >> 4) & 0x3FFFFC0 ) | ($Check1 & 0x3F);
    $Check1 = (($Check1 >> 4) & 0x3FFC00 ) | ($Check1 & 0x3FF);
    $Check1 = (($Check1 >> 4) & 0x3C000 ) | ($Check1 & 0x3FFF);

    $T1 = (((($Check1 & 0x3C0) << 4) | ($Check1 & 0x3C)) <<2 ) | ($Check2 & 0xF0F );
    $T2 = (((($Check1 & 0xFFFFC000) << 4) | ($Check1 & 0x3C00)) << 0xA) | ($Check2 & 0xF0F0000 );

    return ($T1 | $T2);
    }

    // Generate a checksum for the hash
    function CheckHash($Hashnum)
    {
    $CheckByte = 0;
    $Flag = 0;
    $HashStr = sprintf('%u', $Hashnum) ;
    $length = strlen($HashStr);
    for ($i = $length - 1; $i >= 0; $i --) {
    $Re = $HashStr{$i};
    if (1 === ($Flag % 2)) {
    $Re += $Re;
    $Re = (int)($Re / 10) + ($Re % 10);
    }
    $CheckByte += $Re;
    $Flag ++;
    }
    $CheckByte %= 10;
    if (0 !== $CheckByte) {
    $CheckByte = 10 - $CheckByte;
    if (1 === ($Flag % 2) ) {
    if (1 === ($CheckByte % 2)) {
    $CheckByte += 9;
    }
    $CheckByte >>= 1;
    }
    }
    return '7' . $CheckByte . $HashStr;
    }

    // Get the Google Pagerank
    function getPagerank($url) {
    $query = "http://toolbarqueries.google.com/tbr?client=navclient-auto&ch=" . $this->CheckHash($this->HashURL($url)) . "&features=Rank&q=info:" . $url . "&num=100&filter=0";
    $data = $this->file_get_contents_curl($query);
    $pos = strpos($data, "Rank_");
    if($pos !== false){
    $pagerank = substr($data, $pos + 9);
    return trim($pagerank);
    }
    }

    // Use curl the get the file contents
    function file_get_contents_curl($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Set curl to return the data instead of printing it to the browser.
    curl_setopt($ch, CURLOPT_URL, $url);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
    }
    }
    Now how do i take it with a javascript? and add the condition to the input field from Website address (Url) if pagerank of website is smaller than 2 echo error" Pagerank is smaller than 2, website is not accepted.
    BTW, my website is http://www.blowhits.com.

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,683
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by imediazone View Post
    Just noticed, i have the PHP that gets the pagerank, located in a folder components/googlepageranker.php. This is the code inside it.


    Now how do i take it with a javascript? and add the condition to the input field from Website address (Url) if pagerank of website is smaller than 2 echo error" Pagerank is smaller than 2, website is not accepted.
    BTW, my website is http://www.blowhits.com.
    it may be as simple as a PHP script that includes that googlepagerank file, and echos out appropriate message

    getpagerank.php
    Code php:
    <?php
    include('components/googlepageranker.php');
     
    $url = filter_var('url', FILTER_SANITIZE_URL);
    echo getPagerank($url);
    ?>

    which you could then test by going to localhost/getpagerank.php?url=http://www.google.com
    which should then result in a pagerank number being echo'd to the page.

    Once the PHP side of things works, you can then return to JavaScript and use an AJAX request to that getpagerank.php file, and retrieve the pagerank number for a url of interest.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    SitePoint Zealot
    Join Date
    Jan 2011
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    it may be as simple as a PHP script that includes that googlepagerank file, and echos out appropriate message

    getpagerank.php
    Code php:
    <?php
    include('components/googlepageranker.php');
     
    $url = filter_var('url', FILTER_SANITIZE_URL);
    echo getPagerank($url);
    ?>

    which you could then test by going to localhost/getpagerank.php?url=http://www.google.com
    which should then result in a pagerank number being echo'd to the page.

    Once the PHP side of things works, you can then return to JavaScript and use an AJAX request to that getpagerank.php file, and retrieve the pagerank number for a url of interest.
    I get http://www.blowhits.com/getpagerank....www.google.com
    Fatal error: Call to undefined function getPagerank() in /home/blowhits/public_html/getpagerank.php on line 5
    don't understand why, cause function is declared in components/googlepageranker.php.

  8. #8
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,683
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by imediazone View Post
    I get http://www.blowhits.com/getpagerank....www.google.com

    don't understand why, cause function is declared in components/googlepageranker.php.
    Ahh, it seems to be part of a class, so try instead using:

    Code php:
    $googlePageRanker = new GooglePageRanker();
    echo $googlePageRanker->getPagerank($url);
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  9. #9
    SitePoint Zealot
    Join Date
    Jan 2011
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    Ahh, it seems to be part of a class, so try instead using:

    Code php:
    $googlePageRanker = new GooglePageRanker();
    echo $googlePageRanker->getPagerank($url);
    Is not echowing anymore errors, i get now a blank page.
    this is what i have in the getpagerank.php now
    <?php
    include('components/GooglePageRanker.php');
    $googlePageRanker = new GooglePageRanker();
    echo $googlePageRanker->getPagerank($url);
    ?>

  10. #10
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,683
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by imediazone View Post
    Is not echowing anymore errors, i get now a blank page.
    this is what i have in the getpagerank.php now
    It seems that you have missed out on retrieving the $url variable.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  11. #11
    SitePoint Zealot
    Join Date
    Jan 2011
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    It seems that you have missed out on retrieving the $url variable.
    hmm

  12. #12
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,683
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by imediazone View Post
    hmm
    Refer to the filter_var line from post #7
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  13. #13
    SitePoint Zealot
    Join Date
    Jan 2011
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Still nothing..
    This is what i have
    <?php
    include('components/GooglePageRanker.php');
    $url = filter_var('url', FILTER_SANITIZE_URL);
    $googlePageRanker = new GooglePageRanker();
    echo $googlePageRanker->getPagerank($url);
    ?>

  14. #14
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,683
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by imediazone View Post
    Still nothing..
    This is what i have
    Well that works for me. I'm moving this thread over to the PHP forum now, so that someone from there can help you further.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  15. #15
    SitePoint Zealot
    Join Date
    Jan 2011
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, appreciate the help.

  16. #16
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    51
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Stupid question, but have you replaced "url" from filter_var line with actual URL?

  17. #17
    SitePoint Zealot
    Join Date
    Jan 2011
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Avram View Post
    Stupid question, but have you replaced "url" from filter_var line with actual URL?
    LOL, it works like that, don't understand. Which would be the correct variable then
    It seams that it's not "url".

  18. #18
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    51
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If you're submitting via AJAX or FORM (POST method), use this:

    Code:
    $url = filter_var($_POST['url'], FILTER_SANITIZE_URL);
    If it's coming through URL (?url=http://blabla.com) or FORM (GET method) (or AJAX GET) then use $_GET instead of $_POST

  19. #19
    SitePoint Zealot
    Join Date
    Jan 2011
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Avram View Post
    If you're submitting via AJAX or FORM (POST method), use this:

    Code:
    $url = filter_var($_POST['url'], FILTER_SANITIZE_URL);
    If it's coming through URL (?url=http://blabla.com) or FORM (GET method) (or AJAX GET) then use $_GET instead of $_POST
    Working with GET
    Now the interesting part. How do i add it in a input field and don't let the user pass submit the form http://www.blowhits.com/webmaster-su...site-free.html and if it's Pagerank is lower than than one to echo message, pagerank is lower than x.
    I really appreciate your help.

  20. #20
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    51
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Disable form submit button, then when user enters something in the field, you will have to make ajax request to your php page and check what it returns.

    If you are using jQuery, which I recommend, check it's get() method.

    Note: Since anyone can turn off JavaScript, I'd include this check on the server-side also (when URL is submitted, check it's pagerank prior to saving URL in the database).

  21. #21
    SitePoint Zealot
    Join Date
    Jan 2011
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Avram View Post
    Disable form submit button, then when user enters something in the field, you will have to make ajax request to your php page and check what it returns.

    If you are using jQuery, which I recommend, check it's get() method.

    Note: Since anyone can turn off JavaScript, I'd include this check on the server-side also (when URL is submitted, check it's pagerank prior to saving URL in the database).
    So should be smth like
    <script type="text/javascript">
    $.get("getpagerank.php", function(data) {
    if (getPagerank($url) < 2)
    alert("Pagerank Is Smaller than 2");
    });
    </script>

    and on the input field i need to add smth like <input onfocus ?
    I really appreciate your help, sorry for being a noob in jquery /php.

  22. #22
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    51
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code:
    function checkPR() {
      //edit this
      var $btn = $('#your_submit_button_id');
      var $input = $('#your_url_input_id');
    
      //do not edit below unless you know what are you doing
      var url = $.trim($input.val());
    
      $.get('getpagerank.php?url='+url, function(data){
    
        var pr_int = parseInt(data);
    
        if ($.trim(data) == '' || pr_int < 2)
        {
          alert('PageRank of this page is less than 2!');
          $btn.attr('disabled', 'disabled');
        }
        else
        {
          $btn.removeAttr('disabled');
        }
    
      }, 'text');
    }
    Then call this function whenever your input loses focus for example: <input onblur="checkPR()" />

    Or you can modify it a little bit and call it when submit button is clicked.

  23. #23
    SitePoint Zealot
    Join Date
    Jan 2011
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have added this

    <script type="text/javascript">
    function checkPR() {
    var $btn = $('#buttonsubmit');
    var $input = $('#urlpr');
    var url = $.trim($input.val());

    $.get('getpagerank.php?url='+url, function(data){

    var pr_int = parseInt(data);

    if ($.trim(data) == '' || pr_int < 2)
    {
    alert('PageRank of this page is less than 2!');
    $btn.attr('disabled', 'disabled');
    }
    else
    {
    $btn.removeAttr('disabled');
    }

    }, 'text');
    }
    </script>
    and it's sending me this errors.

    (256) TPL: [in webmaster/submitWebsite.tpl line 26]: syntax error: var function does not exist (class.compiler.php, line 501) class.template.php line 703 2-7-13 9:14

    FrontController->dispatch() # line 18, file: /home/blowhits/public_html/index.php
    Controller->render() # line 225, file: /home/blowhits/public_html/core/FrontController.php
    TemplateLiteView->render(Object:WebmasterController) # line 167, file: /home/blowhits/public_html/core/Controller.php
    Template_Lite->fetch("webmaster/submitWebsite.tpl") # line 77, file: /home/blowhits/public_html/views/TemplateLiteView.php
    Template_Lite->_fetch_compile("webmaster/submitWebsite.tpl", null) # line 360, file: /home/blowhits/public_html/components/template_lite/class.template.php
    Template_Lite_Compiler->_compile_file("{capture assign="headData"}
    <META NAME="ROBOTS" CONTENT="NOINDEX...") # line 528, file: /home/blowhits/public_html/components/template_lite/class.template.php
    Template_Lite_Compiler->_compile_tag("var $btn = $('#buttonsubmit');
    var $input = $('#urlpr');
    var...") # line 187, file: /home/blowhits/public_html/components/template_lite/class.compiler.php
    Template_Lite_Compiler->_parse_function("var", null, "$btn = $('#buttonsubmit');
    var $input = $('#urlpr');
    var url...") # line 243, file: /home/blowhits/public_html/components/template_lite/class.compiler.php
    Template_Lite->trigger_error("var function does not exist", "256", "/home/blowhits/public_html/components/template_lite/class.compil...", "501") # line 501, file: /home/blowhits/public_html/components/template_lite/class.compiler.php
    trigger_error("TPL: [in webmaster/submitWebsite.tpl line 26]: syntax error: var...", "256") # line 703, file: /home/blowhits/public_html/components/template_lite/class.template.php

  24. #24
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    51
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Do not put this in a PHP code. This is JavaScript code that has nothing to do with PHP. I have no idea why is your php trying to parse this code...?

  25. #25
    SitePoint Zealot
    Join Date
    Jan 2011
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Avram View Post
    Do not put this in a PHP code. This is JavaScript code that has nothing to do with PHP. I have no idea why is your php trying to parse this code...?
    So where should i add it? In a Jacascript like checkpr.js ? and after include it in the .tpl file?


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •