Seznam srank checker
function to get actual value of Srank. (c)
Jakub Roztocil, used by
rank.isecure.cz
<?php
/**
* @author Jakub Roztocil <jakub@webkitchen.cz>
* @licence GNU GPL v2+
* @param string $url
* @return int S-Rank | -1 on error
*/
function getRank($url) {
$postData = '<?xml version="1.0" encoding="UTF-8"?>' .
'<methodCall>' .
'<methodName>getRank</methodName>' .
'<params>' .
'<param>' .
'<value>' .
'<string>0</string>' .
'</value>' .
'</param>' .
'<param>' .
'<value>' .
'<string>' . htmlspecialchars($url) . '</string>' .
'</value>' .
'</param>' .
'<param>' .
'<value>' .
'<i4>0</i4>' .
'</value>' .
'</param>' .
'</params>' .
'</methodCall>';
$header = "POST /RPC2 HTTP/1.1\r\n";
$header .= "Host: srank.seznam.cz\r\n";
$header .= "Content-Type: text/xml\r\n";
$header .= "Content-Length: " . strlen($postData) . "\r\n";
$header .= "Connection: Close\r\n\r\n";
$errNo = $errStr = '';
$socket = fsockopen('srank.seznam.cz', 80, $errNo, $errStr, 10);
if (!$socket) {
return -1;
}
fwrite($socket, $header . $postData);
$response = '';
while (!feof($socket)) {
$response .= fgets($socket, 128);
}
$response = preg_replace('/^(.+\r\n)+\r\n/', '', $response);
$doc = new DOMDocument;
if (!$doc->loadXml($response)) {
return -1;
}
$xpath = new DOMXPath($doc);
$result = $xpath->evaluate('string(//member[name = "rank"]/value)');
if (!is_numeric($result)) {
return -1;
}
$rank = round((int)$result * 100 / 255);
return $rank;
}
?>
Tagy:
php 59 řádků | 2008-02-04 20:44:27 | air.kadlec@seznam.cz