P You see the QQ space that friend long time no contact?

Source: Internet
Author: User
Afternoon to see the beginning of a popular space, a friend for a long time contact! Contact me Now! Who in their own space to see, pictures on the display of who's QQ and nickname! How is this done? I wrote a little demo here. Get QQ nickname is need to visit a webpage, I have the original class here! It is directly used, there are many ways to get it! But say it directly on the code!
    1. $ment = $_server["Http_referer"];
    2. Preg_match ("#[0-9]{5,11}#", $ment, $RR);
    3. $r = $RR [0];
    4. Include_once ("Curl.class.php");
    5. $curl =new Curl ();
    6. $webtext = $curl->get (' http://redstones.sinaapp.com/apis/qqinfo-service.php?qq= '. $r);
    7. Preg_match (' # ' nickname ":" (. *?) " # ', $webtext, $RR);
    8. $rrr = $RR [1];
    9. Header ("Content-type:image/png");
    10. $im =imagecreatefromjpeg ("1.jpg");
    11. $black = Imagecolorallocate ($im, 56,73,136);
    12. $fnt = "Shenfenzheng. TTF ";
    13. Imagettftext ($im, 26,0,110,100, $black, "Shenfenzheng. TTF ", $rrr);
    14. Imagettftext ($im, 26,0,100,180, $black, "Shenfenzheng. TTF ", $r);
    15. Imagejpeg ($im);
    16. Imagedestroy ($im);
    17. ?>
Copy Code
  1. Class curl{
  2. Curl Handle
  3. private $ch = null;
  4. Information that is set or returned by the server side before and after curl execution
  5. Private $info = Array ();
  6. CURL setopt Info
  7. Private $setopt = Array (
  8. Access to the port, HTTP default is 80
  9. ' Port ' =>80,
  10. Client useragent, such as: "mozilla/4.0", empty then use the user's browser
  11. ' useragent ' = ',
  12. Connection time-out period
  13. ' TimeOut ' =>30,
  14. Whether to use cookies is recommended to open, because the general website will use
  15. ' Usecookie ' =>true,
  16. Whether SSL is supported
  17. ' SSL ' =>false,
  18. Whether the client supports gzip compression
  19. ' Gzip ' =>true,
  20. Whether to use a proxy
  21. ' Proxy ' =>false,
  22. Proxy type, selectable HTTP or SOCKS5
  23. ' Proxytype ' = ' HTTP ',
  24. The host address of the agent, if it is HTTP, it should be written as a URL form such as: "Http://www.proxy.com"
  25. The SOCKS5 method directly writes the host domain name as the IP form, such as: "192.168.1.1"
  26. ' ProxyHost ' = ' http://www.proxy.com ',
  27. Port of the agent host
  28. ' ProxyPort ' =>1234,
  29. Whether the agent wants authentication (HTTP mode)
  30. ' Proxyauth ' =>false,
  31. Authentication method. You can choose BASIC or NTLM
  32. ' Proxyauthtype ' = ' BASIC ',
  33. Authenticated user name and password
  34. ' Proxyauthuser ' = ' user ',
  35. ' Proxyauthpwd ' = ' password ',
  36. );
  37. /**
  38. * Constructor function
  39. *
  40. * @param array $setopt: Please refer to private $setopt to set
  41. */
  42. Public function __construct ($setopt =array ())
  43. {
  44. Merge user settings and default settings for the system
  45. $this->setopt = Array_merge ($this->setopt, $setopt);
  46. Terminate the program if Curl is not installed
  47. Function_exists (' curl_init ') | | Die (' CURL Library is not Loaded ');
  48. Initialization
  49. $this->ch = Curl_init ();
  50. To set the port for a Curl connection
  51. curl_setopt ($this->ch, Curlopt_port, $this->setopt[' PORT ']);
  52. Using proxies
  53. if ($this->setopt[' proxy ') {
  54. $proxyType = $this->setopt[' proxytype ']== ' HTTP '? CURLPROXY_HTTP:CURLPROXY_SOCKS5;
  55. curl_setopt ($this->ch, Curlopt_proxytype, $proxyType);
  56. curl_setopt ($this->ch, Curlopt_proxy, $this->setopt[' proxyhost ']);
  57. curl_setopt ($this->ch, Curlopt_proxyport, $this->setopt[' ProxyPort ']);
  58. Agent to be certified
  59. if ($this->setopt[' Proxyauth ') {
  60. $proxyAuthType = $this->setopt[' proxyauthtype ']== ' BASIC '? CURLAUTH_BASIC:CURLAUTH_NTLM;
  61. curl_setopt ($this->ch, Curlopt_proxyauth, $proxyAuthType);
  62. $user = "[{$this->setopt[' proxyauthuser ']}]:[{$this->setopt[' proxyauthpwd ']}]";
  63. curl_setopt ($this->ch, curlopt_proxyuserpwd, $user);
  64. }
  65. }
  66. if (Ini_get (' open_basedir ') = = "&& ini_get (' safe_mode ' = = ' Off '))
  67. When enabled, the server server returns the "location:" returned to the server recursively in the header
  68. curl_setopt ($this->ch, curlopt_followlocation, true);
  69. Open support for SSL
  70. if ($this->setopt[' SSL ') {
  71. Do not check the source of certification certificate
  72. curl_setopt ($this->ch, Curlopt_ssl_verifypeer, false);
  73. Check that the SSL encryption algorithm exists from the certificate
  74. curl_setopt ($this->ch, Curlopt_ssl_verifyhost, true);
  75. }
  76. Set HTTP headers to support LIGHTTPD server access
  77. $header []= ' Expect: ';
  78. curl_setopt ($this->ch, Curlopt_httpheader, $header);
  79. Set HTTP useragent
  80. $userAgent = $this->setopt[' useragent ')? $this->setopt[' useragent ': $_server[' http_user_agent '];
  81. curl_setopt ($this->ch, curlopt_useragent, $userAgent);
  82. Set the connection wait time, 0 do not wait
  83. curl_setopt ($this->ch, curlopt_connecttimeout, $this->setopt[' TimeOut ');
  84. Set the maximum number of seconds that curl is allowed to execute
  85. curl_setopt ($this->ch, curlopt_timeout, $this->setopt[' TIMEOUT ');
  86. Set whether the client supports gzip compression
  87. if ($this->setopt[' gzip]) {
  88. curl_setopt ($this->ch, curlopt_encoding, ' gzip ');
  89. }
  90. Whether to use cookies
  91. if ($this->setopt[' Usecookie ') {
  92. Generate files that hold temporary cookies (absolute path)
  93. $cookfile = Tempnam (Sys_get_temp_dir (), ' cuk ');
  94. Store cookie information After the connection is closed
  95. curl_setopt ($this->ch, Curlopt_cookiejar, $cookfile);
  96. curl_setopt ($this->ch, Curlopt_cookiefile, $cookfile);
  97. }
  98. Whether the header file information as the data stream output (header information), where the message is retained
  99. curl_setopt ($this->ch, Curlopt_header, true);
  100. The information obtained is returned in the form of a file stream, rather than directly output.
  101. curl_setopt ($this->ch, Curlopt_returntransfer, true);
  102. curl_setopt ($this->ch, Curlopt_binarytransfer, true);
  103. }
  104. /**
  105. * Execute requests in GET mode
  106. *
  107. * @param string $url: Requested URL
  108. * @param array $params: requested parameter, format such as: Array (' ID ' =>10, ' name ' = ' Yuanwei ')
  109. * @param array $referer: The reference page is automatically set when it is empty and must be set if the server has control over it.
  110. * @return Error returned: false returned correctly: result content
  111. */
  112. Public function Get ($url, $params =array (), $referer = ")
  113. {
  114. return $this->_request (' GET ', $url, $params, Array (), $referer);
  115. }
  116. /**
  117. * Execute request as POST
  118. *
  119. * @param string $url: Requested URL
  120. * @param array $params: requested parameter, format such as: Array (' ID ' =>10, ' name ' = ' Yuanwei ')
  121. * @param array $uploadFile: Uploaded files, supporting relative paths, in the following format
  122. * Single File Upload: Array (' img1 ' = './file/a.jpg ')
  123. * Upload multiple files in the same field: Array (' img ' =>array ('./file/a.jpg ', './file/b.jpg '))
  124. * @param array $referer: Referring to the page, referring to the page, is automatically set when empty, if the server has this control, it must be set.
  125. * @return Error returned: false returned correctly: result content
  126. */
  127. Public Function post ($url, $params =array (), $uploadFile =array (), $referer = ")
  128. {
  129. return $this->_request (' POST ', $url, $params, $uploadFile, $referer);
  130. }
  131. /**
  132. * Get error message
  133. *
  134. * @return String
  135. */
  136. Public Function error ()
  137. {
  138. Return Curl_error ($this->ch);
  139. }
  140. /**
  141. * Get the error code
  142. *
  143. * @return int
  144. */
  145. Public Function errno ()
  146. {
  147. Return Curl_errno ($this->ch);
  148. }
  149. /**
  150. * Get all server information and server header information before and after sending the request, where
  151. * [Before]: information set before request
  152. * [after]: All server information after request
  153. * [Header]: Server header message Information
  154. *
  155. * @return Array
  156. */
  157. Public Function GetInfo ()
  158. {
  159. return $this->info;
  160. }
  161. /**
  162. * destructor
  163. *
  164. */
  165. Public Function __destruct ()
  166. {
  167. Turn off Curl
  168. Curl_close ($this->ch);
  169. }
  170. /**
  171. * Private method: Execute final request
  172. *
  173. * @param string $method: HTTP request method
  174. * @param string $url: Requested URL
  175. * @param array $params: Requested parameter
  176. * @param array $uploadFile: Uploaded file (only valid when post)
  177. * @param array $referer: Reference page
  178. * @return Error returned: false returned correctly: result content
  179. */
  180. Private Function _request ($method, $url, $params =array (), $uploadFile =array (), $referer = ")
  181. {
  182. To connect to the URL after the request is made in Get mode
  183. if ($method = = ' GET ') {
  184. $url = $this->_parseurl ($url, $params);
  185. }
  186. Set the requested URL
  187. curl_setopt ($this->ch, Curlopt_url, $url);
  188. If it is a post
  189. if ($method = = ' POST ') {
  190. Send a regular POST request, type: application/x-www-form-urlencoded
  191. curl_setopt ($this->ch, Curlopt_post, true);
  192. Set Post field values
  193. $postData = $this->_parsmencode ($params, false);
  194. /*
  195. If you have uploaded files
  196. if ($uploadFile) {
  197. foreach ($uploadFile as $key = = $file) {
  198. if (Is_array ($file)) {
  199. $n = 0;
  200. foreach ($file as $f) {
  201. File must be an absolute path
  202. $postData [$key. ' ['. $n + +. '] = ' @ '. Realpath ($f);
  203. }
  204. }else{
  205. $postData [$key] = ' @ '. Realpath ($file);
  206. }
  207. }
  208. }
  209. */
  210. PR ($postData); Die
  211. curl_setopt ($this->ch, Curlopt_postfields, $postData);
  212. }
  213. The reference page is set, otherwise it is set automatically
  214. if ($referer) {
  215. curl_setopt ($this->ch, Curlopt_referer, $referer);
  216. }else{
  217. curl_setopt ($this->ch, Curlopt_autoreferer, true);
  218. }
  219. Get information on all settings
  220. $this->info[' before '] = Curl_getinfo ($this->ch);
  221. Start Execution Request
  222. $result = curl_exec ($this->ch);
  223. Get message header
  224. $headerSize = Curl_getinfo ($this->ch, curlinfo_header_size);
  225. $this->info[' header '] = substr ($result, 0, $headerSize);
  226. Remove message Header
  227. $result = substr ($result, $headerSize);
  228. Get all the information that includes the server return
  229. $this->info[' after '] = Curl_getinfo ($this->ch);
  230. If the request succeeds
  231. if ($this->errno () = = 0) {//&& $this->info[' after ' [' http_code '] = = 200
  232. return $result;
  233. }else{
  234. return false;
  235. }
  236. }
  237. /**
  238. * used when returning the parsed Url,get mode
  239. *
  240. * @param string $url: URL
  241. * @param array $params: Parameters added to the URL
  242. * @return String
  243. */
  244. Private Function _parseurl ($url, $params)
  245. {
  246. $FIELDSTR = $this->_parsmencode ($params);
  247. if ($FIELDSTR) {
  248. $url. = Strstr ($url, '? ') ===false? '? ': ' & ';
  249. $url. = $FIELDSTR;
  250. }
  251. return $url;
  252. }
  253. /**
  254. * Encode encoding of parameters
  255. *
  256. * @param array $params: Parameters
  257. * @param bool $isRetStr: true: Returns false as a string: returned as an array
  258. * @return String | | Array
  259. */
  260. Private Function _parsmencode ($params, $isRetStr =true)
  261. {
  262. $FIELDSTR = ";
  263. $SPR = ";
  264. $result = Array ();
  265. foreach ($params as $key = = $value) {
  266. $value = UrlEncode ($value);
  267. $fieldStr. = $spr. $key. ' ='. $value;
  268. $SPR = ' & ';
  269. $result [$key] = $value;
  270. }
  271. Return $ISRETSTR? $FIELDSTR: $result;
  272. }
  273. }
Copy Code
  • 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.