PHP get QQ user nickname and online status (instance analysis) _php 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, 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 &lt;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;
}

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.