如果我们利用php获取QQ用户名与在线状态QQ并未给我们提供api接口了,如果要获取我们可以通过QQ空间或QQ网页版聊天来实现。
QQ通过返回不同的图片,来表示在线或离线,图标也随之变换
既然图片不同,那么,返回的HTTP头信息中的Content-Length 也一定不同,而且,彩色图片一定会比同样子的暗色图片要大,于是,找出某个样式的彩色与暗色图片的中间值,就能达到通过判断头部返回长度的方法来获取QQ在线状态
以下是代码
<?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); } } } ?>
上面比较简单,下面来个更好的
<?php 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", 80))) 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); ?>
例,qq用户昵称和在线状态
<?php //获取QQ状态 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; } } //获取QQ昵称 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]; } //获取QQ姓名 function getQQName($qq) { //$qqArr = include 'friendArr.php';//预先设置的 //$username = $qqArr[$qq]; if (!$username) { $username = getQQNick($qq); } return $username; } ?>
本文地址:
转载随意,但请附上文章地址:-)

一、Iterator和foreach的区别多态差别(foreach底层就是Iterator)Iterator是一个接口类型,他不关心集合或者数组的类型;for和foreach都需要先知道集合的类型,甚至是集合内元素的类型;1.为啥说foreach底层就是Iterator编写的代码:反编译代码:二、foreach与iterator时remove的区别先来看阿里java开发手册但1的时候不会报错,2的时候就会报错(java.util.ConcurrentModificationException)首

php判断foreach循环到第几个的步骤:1、创建一个“$fruits”的数组;2、创建一个计数器变量“$counter”初始值为0;3、使用“foreach”循环遍历数组,并在循环体中增加计数器变量的值,再输出每个元素和它们的索引;4、在“foreach”循环体外输出计数器变量的值,以确认循环到了第几个元素。

当我们在使用 PHP 编写网页时,有时我们需要在当前 PHP 文件中包含其他 PHP 文件中的代码。这时,就可以使用 include 或 include_once 函数来实现文件包含。那么,include 和 include_once 到底有什么区别呢?

这篇文章将为大家详细讲解有关PHP返回一个键值翻转后的数组,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。PHP键值翻转数组键值翻转是一种对数组进行的操作,它将数组中的键和值进行交换,生成一个新的数组,其中原始键作为值,原始值作为键。实现方法在php中,可以通过以下方法对数组进行键值翻转:array_flip()函数:array_flip()函数专门用于键值翻转操作。它接收一个数组作为参数,并返回一个新的数组,其中键和值已交换。$original_array=[

PHP中的explode函数是一种用来将字符串分割成数组的函数,它非常常用且灵活。在使用explode函数的过程中,常常会遇到一些报错和问题,本文将介绍explode函数的基本用法并提供一些解决报错的方法。一、explode函数基本用法在PHP中,explode函数的基本语法如下:explode(string$separator,string$stri

在PHP编程中,处理字符串是一个经常需要进行的操作。其中,分割和合并字符串则是两种常见的需求。为了更方便地进行这些操作,PHP提供了两个非常实用的函数,即explode和implode函数。本文将介绍这两个函数的用法,以及一些实用的技巧。一、explode函数explode函数用于将一个字符串按照指定的分隔符进行分割,并返回一个数组。其函数原型如下:arra

这篇文章将为大家详细讲解有关PHP返回字符串第一个字符的ASCII值,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。PHP返回字符串第一个字符的ASCII值引言在php中,获取字符串第一个字符的ASCII值是一个常见的操作,涉及到字符串处理和字符编码基础知识。ASCII值用于表示字符在计算机系统中的数字值,对于字符比较、数据传输和存储至关重要。过程获取字符串第一个字符的ASCII值涉及以下步骤:获取字符串:确定要获取ASCII值的字符串。它可以是变量、字符串常量

标题:PHP中使用explode函数时常见的错误及解决方案在PHP中,explode函数是用于将字符串分割成数组的常用函数。然而,由于使用不当或者数据格式不正确,可能会导致一些常见的错误。本文将针对在使用explode函数时可能遇到的问题进行分析,并提供解决方案和具体的代码示例。错误一:未传入分隔符参数在使用explode函数时,最常见的错误之一是未传入分隔


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download
The most popular open source editor

Dreamweaver Mac version
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
