Autore Messaggio
07-08-2007, 06:19
Messaggio: #1 (permalink)
Namaless
Forumista Attivo
****
Registrato: Nov 2007
Messaggi: 320
Reputazione:

[NamaPR] Get Pagerank!


Bene.. la notte porta consigli quando non si ha sonno... per cui vado a presentare il nuovo progetto: "NamaPR"

NamaPR e' una classe scritta in PHP che permette tramite una semplice funzione avere il PR (Pagerank) di un dominio.

Per il momento non ho ancora passato lo script a classe effettiva perche' sti' facendo delle prove se usare la classe cosi':

Codice PHP:
echo NamaPR('www.namaless.com'); 

oppure

Codice PHP:
echo new NamaPR('www.namaless.com'); 

Aspettavo proprio di pubblicarlo qui.. Abbr

Per quanto riguarda la classe basta salvare il tutto in un file tipo "NamaPR.class.php" e nel solito posto creare un file "index.php", nel file "NamaPR.class.php" ci mettete questo codice:

Codice PHP:
<?php
/**
 *    Project:    NamaPR
 *    Version:    1.0
 ***********************************************************************
 *    Copyright (C) 1981-2007 Namaless ( http://www.namaless.com/ )
 *
 *    This program is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU General Public License
 *    as published by the Free Software Foundation; either version 2
 *    of the License, or (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 ***********************************************************************
 *
 *    @link           http://www.namaless.com/
 *    @copyright      1981-2007 Namaless ( http://www.namaless.com/ )
 *
*/

define ('GOOGLE_MAGIC'0xE6359A60);

function 
_zeroFill($a$b)
{
    
$z hexdec(80000000);

    if (
$z $a)
    {
        
$a = ($a>>1);
        
$a &= (~$z);
        
$a |= 0x40000000;
        
$a = ($a>>($b-1));
    }
    else
    {
        
$a = ($a>>$b);
    }

    return 
$a;
}

function 
_xor32($a$b)
{
    return 
_int32($a) ^ _int32($b);
}

function 
_int32($x)
{
    return 
unserialize("i:$x;");
}

function 
_mix($a$b$c)
{
    
$a -= $b$a -= $c$a _xor32($a_zeroFill($c13));
    
$b -= $c$b -= $a$b _xor32($b$a<<8);
    
$c -= $a$c -= $b$c _xor32($c_zeroFill($b13));
    
$a -= $b$a -= $c$a _xor32($a_zeroFill($c12));
    
$b -= $c$b -= $a$b _xor32($b$a<<16);
    
$c -= $a$c -= $b$c _xor32($c_zeroFill($b5));
    
$a -= $b$a -= $c$a _xor32($a_zeroFill($c3));
    
$b -= $c$b -= $a$b _xor32($b$a<<10);
    
$c -= $a$c -= $b$c _xor32($c_zeroFill($b15));

    return array(
$a$b$c);
}

function 
_GoogleCH($url$length null$init GOOGLE_MAGIC)
{
    if (
is_null($length))
    {
        
$length sizeof($url);
    }

    
$a $b 0x9E3779B9;
    
$c $init;
    
$k 0;
    
$len $length;

    while (
$len >= 12)
    {
        
$a += ($url[$k+0] +($url[$k+1]<<8) +($url[$k+2]<<16) +($url[$k+3]<<24));
        
$b += ($url[$k+4] +($url[$k+5]<<8) +($url[$k+6]<<16) +($url[$k+7]<<24));
        
$c += ($url[$k+8] +($url[$k+9]<<8) +($url[$k+10]<<16)+($url[$k+11]<<24));
        
$_mix _mix($a$b$c);
        
$a $_mix[0]; $b $_mix[1]; $c $_mix[2];
        
$k += 12;
        
$len -= 12;
    }
    
$c += $length;

    switch(
$len)
    {
        case 
11$c+=($url[$k+10]<<24);
        case 
10$c+=($url[$k+9]<<16);
        case 
$c+=($url[$k+8]<<8);
        case 
$b+=($url[$k+7]<<24);
        case 
$b+=($url[$k+6]<<16);
        case 
$b+=($url[$k+5]<<8);
        case 
$b+=($url[$k+4]);
        case 
$a+=($url[$k+3]<<24);
        case 
$a+=($url[$k+2]<<16);
        case 
$a+=($url[$k+1]<<8);
        case 
$a+=($url[$k+0]);
    }
    
$_mix _mix($a$b$c);

    return 
$_mix[2];
}

function 
_strord($string)
{
    for (
$i 0$i strlen($string); $i++)
    {
        
$result[$i] = ord($string{$i});
    }
    return 
$result;
}

function 
NamaPR($url)
{
    
$ch "6" _GoogleCH(_strord("info:" $url));

    
$pagerank = -1;
    
$fp = @fsockopen("www.google.com"80$errno$errstr10);

    if (!
$fp)
    {
        echo 
"$errstr ($errno)<br />\n";
    }
    else
    {
        
$out  "GET /search?client=navclient-auto&ch=" $ch .  "&features=Rank&q=info:" $url " HTTP/1.1\r\n" ;
        
$out .= "Host: www.google.com\r\n" ;
        
$out .= "Connection: Close\r\n\r\n" ;
        @
fwrite($fp$out);

        while (!
feof($fp))
        {
            
$data = @fgets($fp128);
            
$pos  strpos($data"Rank_");

            if (
$pos !== FALSE)
            {
                
$pagerank trim(substr($data$pos 9));
            }
        }

        @
fclose ($fp);
    }
    return 
$pagerank;
}
?>

mentre in "index.php" ci mettere questo:

Codice PHP:
<?php
// richiama la classe NamaPR
require_once('NamaPR.class.php');

echo 
NamaPR($_GET['url']);
?>

Cosi' per vedere il pr di un dominio bastera' usare il link "http://www.sito.it/index.php?url=www.namaless.com" e verra' restituito in numero il pr dell'url.

Suggerimenti e news sul mio blog: http://www.namaless.com/page/23/namapr-g...erank.html


Visita sito dell'autore trova tutti i messaggi dell'autore Quota questo messaggio nella risposta