PHP implementation QQ Hanging Machine Programming (2): Take QQ Online status

Source: Internet
Author: User
Tags chr count socket
This is a PHP access QQ online status program. The principle is very simple, omit not to say, can see the code. Using the interactive state of the service to take the state.

The usage is also simple, the incoming parameter is QQ number, function returns 1 QQ online, function return 0 means QQ not line, return less than 0 means error.

Note: QQ is required to use QQ2004II Beta1 or above version of the landing can be detected.


The code is as follows:

<?php
Vim:set expandtab tabstop=4 shiftwidth=4 fdm=marker:
// | Copyright (c) fishchen.
// | Authors:fishchen, A.
$Id $

/**
* @note LICENSE:GNU general public License (GPL) version 2
* @file $RCSfile $
* @version 1.0
* @author Fishchen
* @date 2004/12/24 11:00:00 (Merry xmas)
* @brief get QQ Online Status.
*/

/* {{{function tphp_qq_online ($uin) */
/**
* Get QQ Online status.
*
* @note Need User login QQ with qq2004iibeta1 or Laster.
* @param int $uin QQ number.
* @retval int $ret 1:online, 0:offline, <0:error.
*/
function Tphp_qq_online ($uin)
{
$reques = "Get/pa?p=1:" $uin. " : 1 http/1.1\r\n ";
$reques. = "host:wpa.qq.com\r\n";
$reques. = "user-agent:php_qq_spy\r\n\r\n";

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 ("\ r \ n", $respon);
for ($i =0; $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);
}
/* }}} */

/* {{{sample:
echo Tphp_qq_online (80000800);
}}} */

?>


Note: For the above, you can use this reference to write a version of other languages;

Attached: No program, get a user QQ online status (save the following code as an. htm file)

<script language=vbscript>

Function GetURL (URL)

Set retrieval = CreateObject ("Microsoft.XMLHTTP")

With retrieval

. Open "Get", url, False, "", ""

. Send

GetURL =. ResponseText

End With

Set retrieval = Nothing

End Function

</script>


Small icon:

<script language=vbscript>

Dim T,start,length,picurl

T=geturl ("http://search.tencent.com/cgi-bin/friend/oicq_find?oicq_no=1924192")


Start=instr (1,t, "Showresult" ("+CHR" (34))

Start=instr (start,t, "http://")

Length=instr (START,T,CHR) + "," +CHR)-start

Picurl=mid (T,start,length)

′document.write "
document.write "<a href=http://search.tencent.com/cgi-bin/friend/user_show_info?ln=1924192
Target=_blank title=qq:1924192>Height=16 border=0></a> "

</script>


Large icon:

<script language=vbscript>

Dim T,start,length,picurl

T=geturl ("http://search.tencent.com/cgi-bin/friend/user_show_info?ln=1924192")


Start=instr (1,t, "img height=32")

Start=instr (start,t, "http://")

Length=instr (START,T,CHR) + "width=32")-start

Picurl=mid (T,start,length)

′document.write "
document.write "<a href=http://search.tencent.com/cgi-bin/friend/user_show_info?ln=1924192
Target=_blank title=qq:1924192>Height=32 border=0></a> "

</script>


RELATED links: Using PHP to implement QQ hanging machine program

Related Article

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.