PHP gets QQ user nickname and online status instance

Source: Internet
Author: User

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, the color picture must be larger than the same dark color picture, so, find a style of color and dark image of the middle value, To get the QQ online status by judging the length of the head return

Here's the Code

The code is as follows


<?php

function 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 a little more simple.

The code is 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

The code is 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 '; pre-set
//$username = $QQARR [ $QQ];
if (! $username) {
$username = Getqqnick ($QQ);
}
return $username;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.