QQ through the return of different pictures, to express online or offline, the icon also changes, since the picture is different, then, the return of the HTTP header information in the Content-length also must be different, and, color pictures must be more than the same dark color picture to be big, so, Find the middle value of a color and dark picture of a style to get the QQ online status by judging how long the head returns
Here's the Code
Copy Code code as follows:
<?phpfunction Get_qq_status ($uin)
{
error_reporting (0);
$f =file_get_contents (' http://wpa.qq.com/pa?p=1: '. $uin. : 4 ');
if (! $f) return (true);
foreach ($http _response_header as $val)
{
if (Strpos ($val, ' content-length ')!==false)
{
Return (Intval (substr ($val, 16,50)) >1000);
}
}
}
?>
It's easier to get a better
Copy Code code as follows:
;?
function Tphp_qq_online ($uin)
{
$reques = "Get/pa?p=1:" $uin. " : 1 Http/1.1rn ";
$reques. = "HOST:WPA.QQ.COMRN";
$reques. = "User-agent:php_qq_spyrnrn";
if ($socket = Socket_create (Af_inet, Sock_stream, sol_tcp)) return (-1);
if (Socket_connect ($socket, "wpa.qq.com")) return (-1);
if (Socket_write ($socket, $reques)) return (-1);
if ($respon = Socket_read ($socket, 1024, Php_binary_read)) return (-1);;
Socket_close ($socket);
$field = Explode ("rn", $respon);
for ($i =0; $i <count ($field); $i + +) {
if (strncasecmp ($field [$i], "Location:", 9) = = 0) {
if (Strpos ($field [$i], "online") {
$ret = 1;
} else if (Strpos ($field [$i], "offline")) {
$ret = 0;
} else {
$ret =-1;
}//If
break;
}//If
}//For
return ($ret);
}
/* }}} */
echo Tphp_qq_online (561272831);
?>
example, QQ user nickname and online status
Copy Code code as follows:
Get QQ Status
function Getqqstate ($QQ) {
$url = ' http://wpa.qq.com/pa?p=2: '. $qq. ': 41&r= '. Time ();
$headInfo = Get_headers ($url, 1);
$length = $headInfo [' content-length '];
if ($length ==1243) {
return true;
}else {
return false;
}
}
Get QQ Nickname
function Getqqnick ($QQ) {
$str = file_get_contents (' http://r.qzone.qq.com/cgi-bin/user/cgi_personal_card?uin= '. $qq);
$pattern = '/'. Preg_quote (' nickname ': "', '/')." (.*?)'. Preg_quote (', ', '/'). ' /I ';
Preg_match ($pattern, $str, $result);
return $result [1];
}
Get QQ Name
function Getqqname ($QQ) {
$QQARR = include ' friendarr.php ';//Preset
$username = $QQARR [$QQ];
if (! $username) {
$username = Getqqnick ($QQ);
}
return $username;
}