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!
- $ment = $_server["Http_referer"];
- Preg_match ("#[0-9]{5,11}#", $ment, $RR);
- $r = $RR [0];
- Include_once ("Curl.class.php");
- $curl =new Curl ();
- $webtext = $curl->get (' http://redstones.sinaapp.com/apis/qqinfo-service.php?qq= '. $r);
- Preg_match (' # ' nickname ":" (. *?) " # ', $webtext, $RR);
- $rrr = $RR [1];
- Header ("Content-type:image/png");
- $im =imagecreatefromjpeg ("1.jpg");
- $black = Imagecolorallocate ($im, 56,73,136);
- $fnt = "Shenfenzheng. TTF ";
- Imagettftext ($im, 26,0,110,100, $black, "Shenfenzheng. TTF ", $rrr);
- Imagettftext ($im, 26,0,100,180, $black, "Shenfenzheng. TTF ", $r);
- Imagejpeg ($im);
- Imagedestroy ($im);
- ?>
Copy Code
-
- Class curl{
- Curl Handle
- private $ch = null;
- Information that is set or returned by the server side before and after curl execution
- Private $info = Array ();
- CURL setopt Info
- Private $setopt = Array (
- Access to the port, HTTP default is 80
- ' Port ' =>80,
- Client useragent, such as: "mozilla/4.0", empty then use the user's browser
- ' useragent ' = ',
- Connection time-out period
- ' TimeOut ' =>30,
- Whether to use cookies is recommended to open, because the general website will use
- ' Usecookie ' =>true,
- Whether SSL is supported
- ' SSL ' =>false,
- Whether the client supports gzip compression
- ' Gzip ' =>true,
- Whether to use a proxy
- ' Proxy ' =>false,
- Proxy type, selectable HTTP or SOCKS5
- ' Proxytype ' = ' HTTP ',
- The host address of the agent, if it is HTTP, it should be written as a URL form such as: "Http://www.proxy.com"
- The SOCKS5 method directly writes the host domain name as the IP form, such as: "192.168.1.1"
- ' ProxyHost ' = ' http://www.proxy.com ',
- Port of the agent host
- ' ProxyPort ' =>1234,
- Whether the agent wants authentication (HTTP mode)
- ' Proxyauth ' =>false,
- Authentication method. You can choose BASIC or NTLM
- ' Proxyauthtype ' = ' BASIC ',
- Authenticated user name and password
- ' Proxyauthuser ' = ' user ',
- ' Proxyauthpwd ' = ' password ',
- );
- /**
- * Constructor function
- *
- * @param array $setopt: Please refer to private $setopt to set
- */
- Public function __construct ($setopt =array ())
- {
- Merge user settings and default settings for the system
- $this->setopt = Array_merge ($this->setopt, $setopt);
- Terminate the program if Curl is not installed
- Function_exists (' curl_init ') | | Die (' CURL Library is not Loaded ');
- Initialization
- $this->ch = Curl_init ();
- To set the port for a Curl connection
- curl_setopt ($this->ch, Curlopt_port, $this->setopt[' PORT ']);
- Using proxies
- if ($this->setopt[' proxy ') {
- $proxyType = $this->setopt[' proxytype ']== ' HTTP '? CURLPROXY_HTTP:CURLPROXY_SOCKS5;
- curl_setopt ($this->ch, Curlopt_proxytype, $proxyType);
- curl_setopt ($this->ch, Curlopt_proxy, $this->setopt[' proxyhost ']);
- curl_setopt ($this->ch, Curlopt_proxyport, $this->setopt[' ProxyPort ']);
- Agent to be certified
- if ($this->setopt[' Proxyauth ') {
- $proxyAuthType = $this->setopt[' proxyauthtype ']== ' BASIC '? CURLAUTH_BASIC:CURLAUTH_NTLM;
- curl_setopt ($this->ch, Curlopt_proxyauth, $proxyAuthType);
- $user = "[{$this->setopt[' proxyauthuser ']}]:[{$this->setopt[' proxyauthpwd ']}]";
- curl_setopt ($this->ch, curlopt_proxyuserpwd, $user);
- }
- }
- if (Ini_get (' open_basedir ') = = "&& ini_get (' safe_mode ' = = ' Off '))
- When enabled, the server server returns the "location:" returned to the server recursively in the header
- curl_setopt ($this->ch, curlopt_followlocation, true);
- Open support for SSL
- if ($this->setopt[' SSL ') {
- Do not check the source of certification certificate
- curl_setopt ($this->ch, Curlopt_ssl_verifypeer, false);
- Check that the SSL encryption algorithm exists from the certificate
- curl_setopt ($this->ch, Curlopt_ssl_verifyhost, true);
- }
- Set HTTP headers to support LIGHTTPD server access
- $header []= ' Expect: ';
- curl_setopt ($this->ch, Curlopt_httpheader, $header);
- Set HTTP useragent
- $userAgent = $this->setopt[' useragent ')? $this->setopt[' useragent ': $_server[' http_user_agent '];
- curl_setopt ($this->ch, curlopt_useragent, $userAgent);
- Set the connection wait time, 0 do not wait
- curl_setopt ($this->ch, curlopt_connecttimeout, $this->setopt[' TimeOut ');
- Set the maximum number of seconds that curl is allowed to execute
- curl_setopt ($this->ch, curlopt_timeout, $this->setopt[' TIMEOUT ');
- Set whether the client supports gzip compression
- if ($this->setopt[' gzip]) {
- curl_setopt ($this->ch, curlopt_encoding, ' gzip ');
- }
- Whether to use cookies
- if ($this->setopt[' Usecookie ') {
- Generate files that hold temporary cookies (absolute path)
- $cookfile = Tempnam (Sys_get_temp_dir (), ' cuk ');
- Store cookie information After the connection is closed
- curl_setopt ($this->ch, Curlopt_cookiejar, $cookfile);
- curl_setopt ($this->ch, Curlopt_cookiefile, $cookfile);
- }
- Whether the header file information as the data stream output (header information), where the message is retained
- curl_setopt ($this->ch, Curlopt_header, true);
- The information obtained is returned in the form of a file stream, rather than directly output.
- curl_setopt ($this->ch, Curlopt_returntransfer, true);
- curl_setopt ($this->ch, Curlopt_binarytransfer, true);
- }
- /**
- * Execute requests in GET mode
- *
- * @param string $url: Requested URL
- * @param array $params: requested parameter, format such as: Array (' ID ' =>10, ' name ' = ' Yuanwei ')
- * @param array $referer: The reference page is automatically set when it is empty and must be set if the server has control over it.
- * @return Error returned: false returned correctly: result content
- */
- Public function Get ($url, $params =array (), $referer = ")
- {
- return $this->_request (' GET ', $url, $params, Array (), $referer);
- }
- /**
- * Execute request as POST
- *
- * @param string $url: Requested URL
- * @param array $params: requested parameter, format such as: Array (' ID ' =>10, ' name ' = ' Yuanwei ')
- * @param array $uploadFile: Uploaded files, supporting relative paths, in the following format
- * Single File Upload: Array (' img1 ' = './file/a.jpg ')
- * Upload multiple files in the same field: Array (' img ' =>array ('./file/a.jpg ', './file/b.jpg '))
- * @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.
- * @return Error returned: false returned correctly: result content
- */
- Public Function post ($url, $params =array (), $uploadFile =array (), $referer = ")
- {
- return $this->_request (' POST ', $url, $params, $uploadFile, $referer);
- }
- /**
- * Get error message
- *
- * @return String
- */
- Public Function error ()
- {
- Return Curl_error ($this->ch);
- }
- /**
- * Get the error code
- *
- * @return int
- */
- Public Function errno ()
- {
- Return Curl_errno ($this->ch);
- }
- /**
- * Get all server information and server header information before and after sending the request, where
- * [Before]: information set before request
- * [after]: All server information after request
- * [Header]: Server header message Information
- *
- * @return Array
- */
- Public Function GetInfo ()
- {
- return $this->info;
- }
- /**
- * destructor
- *
- */
- Public Function __destruct ()
- {
- Turn off Curl
- Curl_close ($this->ch);
- }
- /**
- * Private method: Execute final request
- *
- * @param string $method: HTTP request method
- * @param string $url: Requested URL
- * @param array $params: Requested parameter
- * @param array $uploadFile: Uploaded file (only valid when post)
- * @param array $referer: Reference page
- * @return Error returned: false returned correctly: result content
- */
- Private Function _request ($method, $url, $params =array (), $uploadFile =array (), $referer = ")
- {
- To connect to the URL after the request is made in Get mode
- if ($method = = ' GET ') {
- $url = $this->_parseurl ($url, $params);
- }
- Set the requested URL
- curl_setopt ($this->ch, Curlopt_url, $url);
- If it is a post
- if ($method = = ' POST ') {
- Send a regular POST request, type: application/x-www-form-urlencoded
- curl_setopt ($this->ch, Curlopt_post, true);
- Set Post field values
- $postData = $this->_parsmencode ($params, false);
- /*
- If you have uploaded files
- if ($uploadFile) {
- foreach ($uploadFile as $key = = $file) {
- if (Is_array ($file)) {
- $n = 0;
- foreach ($file as $f) {
- File must be an absolute path
- $postData [$key. ' ['. $n + +. '] = ' @ '. Realpath ($f);
- }
- }else{
- $postData [$key] = ' @ '. Realpath ($file);
- }
- }
- }
- */
- PR ($postData); Die
- curl_setopt ($this->ch, Curlopt_postfields, $postData);
- }
- The reference page is set, otherwise it is set automatically
- if ($referer) {
- curl_setopt ($this->ch, Curlopt_referer, $referer);
- }else{
- curl_setopt ($this->ch, Curlopt_autoreferer, true);
- }
- Get information on all settings
- $this->info[' before '] = Curl_getinfo ($this->ch);
- Start Execution Request
- $result = curl_exec ($this->ch);
- Get message header
- $headerSize = Curl_getinfo ($this->ch, curlinfo_header_size);
- $this->info[' header '] = substr ($result, 0, $headerSize);
- Remove message Header
- $result = substr ($result, $headerSize);
- Get all the information that includes the server return
- $this->info[' after '] = Curl_getinfo ($this->ch);
- If the request succeeds
- if ($this->errno () = = 0) {//&& $this->info[' after ' [' http_code '] = = 200
- return $result;
- }else{
- return false;
- }
- }
- /**
- * used when returning the parsed Url,get mode
- *
- * @param string $url: URL
- * @param array $params: Parameters added to the URL
- * @return String
- */
- Private Function _parseurl ($url, $params)
- {
- $FIELDSTR = $this->_parsmencode ($params);
- if ($FIELDSTR) {
- $url. = Strstr ($url, '? ') ===false? '? ': ' & ';
- $url. = $FIELDSTR;
- }
- return $url;
- }
- /**
- * Encode encoding of parameters
- *
- * @param array $params: Parameters
- * @param bool $isRetStr: true: Returns false as a string: returned as an array
- * @return String | | Array
- */
- Private Function _parsmencode ($params, $isRetStr =true)
- {
- $FIELDSTR = ";
- $SPR = ";
- $result = Array ();
- foreach ($params as $key = = $value) {
- $value = UrlEncode ($value);
- $fieldStr. = $spr. $key. ' ='. $value;
- $SPR = ' & ';
- $result [$key] = $value;
- }
- Return $ISRETSTR? $FIELDSTR: $result;
- }
- }
Copy Code |