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.

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.

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 &gt;&gt;= 2;
  $Check1 = (($Check1 &gt;&gt; 4) & 0x3FFFFC0 ) | ($Check1 & 0x3F);
  $Check1 = (($Check1 &gt;&gt; 4) & 0x3FFC00 ) | ($Check1 & 0x3FF);
  $Check1 = (($Check1 &gt;&gt; 4) & 0x3C000 ) | ($Check1 & 0x3FFF);

  $T1 = (((($Check1 & 0x3C0) &lt;&lt; 4) | ($Check1 & 0x3C)) &lt;&lt;2 ) | ($Check2 & 0xF0F );
  $T2 = (((($Check1 & 0xFFFFC000) &lt;&lt; 4) | ($Check1 & 0x3C00)) &lt;&lt; 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.

it may be as simple as a PHP script that includes that googlepagerank file, and echos out appropriate message

getpagerank.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.php?url=http://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.

Ahh, it seems to be part of a class, so try instead using:


$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);
?>

It seems that you have missed out on retrieving the $url variable.

hmm

Refer to the filter_var line from post #7

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);
?>

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.

Ok, appreciate the help.

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 :frowning:
It seams that it’s not “url”.

If you’re submitting via AJAX or FORM (POST method), use this:

$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-submit-website-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.

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).