得到QQ号码的在线状态

原理很简单,用php_Curl的批量类去得到QQ在线状态图片的Header,然后对比Content-Length的大小..就知道在线与否了.
以下的 'http://wpa.qq.com/pa?p=2:121711090:3' 在线大小为 1638
//自己改一下print_r
//也可以改成类.
//curl_multi_class.php的类在http://www.cnblogs.com/wc1217/archive/2012/03/08/2387565.html
 
  1: <?php
  2: $qqData = empty($_POST['qqline']) ? null : $_POST['qqline'];
  3: if(!empty($qqData)){
  4:     $qqData = explode(",", $qqData);
  5:     array_walk($qqData, create_function('&$value, $key', '/*if(is_numeric($value)) */$value = "http://wpa.qq.com/pa?p=2:" . $value . ":3";'));
  6: 
  7:     require_once 'curl_multi_class.php';
  8:     $multi = new curl_multi();
  9:     $multi->setUrlList($qqData);
 10:     $multi->setOpt(array('CURLOPT_NOBODY' => 1, 'CURLOPT_HEADER' => 1));
 11:     $urlHeader = $multi->exec();
 12:     $line = array();
 13:     preg_match_all('/Content-Length: (\w{4})\b/', implode('', $urlHeader), $line);
 14:     //print_r($line);
 15:     if(isset($line[1]) && is_array($line[1]))
 16:         array_walk($line[1], create_function('&$value, $key', '$value = $value == 1638 && is_numeric($value);'));
 17:     print_r($line[1]);
 18: }
 19: ?>
 20: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 21: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
 22:     <head>
 23:         <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
 24:         <title></title>
 25:     </head>
 26:     <body>
 27:         <form action="" method="post">
 28:             <textarea name="qqline" id="" cols="30" rows="10">492726616,352037149,1145730003,121711090</textarea>
 29:             <input type="submit" value="提交" />
 30:         </form>
 31: 
 32:     </body>
 33:     <script type="text/javascript">
 34:     </script>
 35: </html>
posted @ 2012-03-15 12:42  无嗔  阅读(275)  评论(0编辑  收藏  举报