Main Menu




browser lang:en

Users Area

Client Login

today cache size is:223155

 

Holyguard rss
rss 2.0 for all sections

 

Portfolio

Some of my projects:
CTIBA
MA-NO Web Agency
BluPool
L'Pratone
Travel in Hotel
Yacht Elements
AbruzzoWeb
Il Mastino
CSI Teramo
Innovazione S.p.a.




Commenti

Aiuto
04/09/2010 by ProgXalpha

19/08/2010 by
ciao jackall
17/07/2010 by marco
aiuto
17/07/2010 by marco
RE: Domanda
08/05/2010 by holyguard
Domanda
05/05/2010 by pryons
Ringraziamento
15/04/2010 by Yuriy, webmaster
edu
12/04/2010 by eduala@libero.it

Leggi tutto »


RAPIDQ

Rapid-Q:The lost files
My old library where i have collected all the rapidq scripts and italian help


Today my pagerank is: Free Page Rank Tool

PHP - Uno script per calcolare il PageRank di Google

Il PageRank è un algoritmo che usa Google per valutare la credibilità e l'autorevolezza delle pagine Web. Il meccanismo su cui si basa è che se una pagina riceve molti collegamenti da altre fonti autorevoli, allora è molto probabilmente anch'essa una fonte autorevole. Il nome PageRank è un marchio registrato di Google e l'algoritmo è stato brevettato: U.S. Patent 6,285,999

Il PageRank è normalmente visualizzato anche nella barra degli strumenti di Google ed è uno strumento utile per chi fa ottimizzazione delle pagine per i motori di ricerca, dato che i siti con alto pagerank vengono visualizzati prima.

 

Come si fa a sapere il pagerank di una pagina? E' sufficiente interrogare un server di Google con un collegamento dove a Google vengono passati l'URL della pagina e un Hash di controllo.

La difficoltà in questo caso sta nel calcolo dell'hash, ma non tanto per l'algoritmo in se che è pubblico, quanto per il fatto che il PHP non gestisce correttamente gli interi sopra 32 bit, pertanto, se nel calcolo dell'hash si ha un'intero di più di 32 bit, va calcolato il modulo a 2^32.

 

//www.lampdeveloper.co.uk/
/*
 * convert a string to a 32-bit integer
 */
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;
}

/* 
 * Genearate a hash for a url
 */
function HashURL($String)
{
    $Check1 = StrToNum($String, 0x1505, 0x21);
    $Check2 = 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);
}

/* 
 * genearate a checksum for the hash string
 */
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;
}

function getpagerank($url) {

$fp = fsockopen("toolbarqueries.google.com", 80, $errno, $errstr, 30);
if (!$fp) {
   echo "$errstr ($errno)
\n"; } else { $out = "GET /search?client=navclient-auto&ch=".CheckHash(HashURL($url))."&features=Rank&q=info:".$url."&num=100&filter=0 HTTP/1.1\r\n"; $out .= "Host: toolbarqueries.google.com\r\n"; $out .= "User-Agent: Mozilla/4.0 (compatible; GoogleToolbar 2.0.114-big; Windows XP 5.1)\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); //$pagerank = substr(fgets($fp, 128), 4); //echo $pagerank; while (!feof($fp)) { $data = fgets($fp, 128); $pos = strpos($data, "Rank_"); if($pos === false){} else{ $pagerank = substr($data, $pos + 9); echo $pagerank; } } fclose($fp); } } echo getpagerank('holyguard.net');

Rating:
46
25 votes
(thanks!)

Commenti

RE: Domanda by holyguard

08/05/2010 
Semplicemente non devi includere la parte di link http://

per esempio per questa pagina il pagerank si calcola cosí:
echo getpagerank('www.holyguard.net/it/detail/scripts-e-tutorials/php-uno-script-per-calcolare-il-pagerank-di-google/1/52/357/');

il risultato sará 2

ciao!


Domanda by pryons

05/05/2010 
Script perfetto. Complimenti.
Ho implementato le immagini dei pr da 1 a 10. Volevo fare una domanda:
come posso passare una variabile alla funzione getpagerank per avere il pr di ciascuna pagina del mio sito?

ho provato cosi, ma non funziona:

<?php
$pagina = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
echo getpagerank($pagina);
?>

Spero possiate aiutarmi.
Grazie


funziona!!! by Andrea Giavara

20/01/2010 
Funziona, grazie mille!
Blog molto ricco di informazioni!

Ciao a tutti
Andrea


questo funziona by admin

20/01/2010 


??? by Andrea Giavra

19/01/2010 
ma se è appena stato pubblicato 10/01/2010???
É già vecchiO???


script obsoleto by holy

19/01/2010 
questo script é obsoleto, va cambiato con uno funzionante


funzioni by Andrea Giavra

18/01/2010 
É troppo chiedere poi come richiamare le funzioni??
Ciao grazie!


Inserisci un commento

Titolo
Messaggio
Nome Utente
e-mail (se vuoi ricevere le risposte a questo post anche via mail)

Videos


Contenuti

Search Engine Optimization - 130 parametri usati da google per valutare il tuo sito

26/08/2010 

Con l'avvento di caffeine molti webmaster si sono trovati a dover rivedere tutte le strategie SEO per i…

in:Scripts e tutorials (0 commenti)

test

19/08/2010 

test

in:PHP Scripts (0 commenti)

Artweaver

28/05/2010 

Artweaver è un programma di disegno dotato di un'infinità di pennelli con cui sperimentare nuove tecniche grafiche.…

in:Software Open Source (0 commenti)

Configurare Domini e Sottodomini con BIND + Postfix

23/03/2010 

Con Bind, la configurazione di domini e sottodomini è abbastanza semplice....l'elemento più importante è il cosidetto zone-file, che…

in:Apache (0 commenti)

hkit - classi in php per il parsing dei microformats

05/03/2010 

hkit é un tool, o meglio, una classe in PHP5 per la estrazione dei piú comuni microformati.  La pagina…

in:PHP Scripts (0 commenti)

Certificati Java

01/03/2010 

Dopo circa un anno ho ritirato i certificati che attestano i miei corsi di Java...purtroppo manca il terzo…

in:Blog (3 commenti)

SVNWeaver, integrare subeversion in Dreamweaver

19/02/2010 

SVNWeaver é una estensione per Dreamweaver che permette di integrare il TortoiseSVN nei menú del Dreamweaver. Devo dire…

in:Applicazioni di sviluppo web (0 commenti)

Inserisci Google BUZZ nel tuo sito con Google Buzz Widget Jquery Plugin

15/02/2010 

Questo è un widget di jQuery per il nuovo social network di Google-Buzz-che è possibile incorporare ovunque per…

in:Scripts e tutorials (0 commenti)

Leggi tutto »


Tag Clouds


Search Engine Optimization parametri usati google valutare sitotestArtweaverConfigurare Domini Sottodomini BIND Postfixhkit classi parsing microformatsCertificati JavaSVNWeaver integrare subeversion DreamweaverInserisci Google BUZZ sito Google Buzz Widget Jquery Plugin


Add to Technorati Favorites