In the afternoon, I saw a popular space. my friends have been in touch for a long time! Contact me! The QQ and nickname of the person who sees it in his own space are displayed on the picture! How is this done? I wrote a demo here. To get QQ nicknames, you need to access a webpage. I have the original class here! It is used directly, and there are many ways to get it! But let's talk about code directly!
- $ 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, 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 );
- ?>
- Class Curl {
- // CURL handle
- Private $ ch = null;
- // Information set before and after CURL execution or returned by the server
- Private $ info = array ();
- // Curl setopt information
- Private $ setopt = array (
- // The Access Port. the default http port is 80.
- 'Port' => 80,
- // Client USERAGENT, for example, "Mozilla/4.0". if it is null, use the user's browser.
- 'Useragent' => '',
- // Connection timeout
- 'Timeout' => 30,
- // Whether to use cookies. we recommend that you enable them because they are usually used by websites.
- 'Usecookier' => true,
- // Whether SSL is supported
- 'SSL '=> false,
- // Whether the client supports gzip compression
- 'Gzip' => true,
- // Use proxy?
- 'Proxy' => false,
- // Proxy type, which can be HTTP or SOCKS5
- 'Xytype' => 'http ',
- // The host address of the proxy, if it is HTTP, you need to write the URL form such as: "http://www.proxy.com"
- // In SOCKS5 mode, the host domain name is directly written as an IP address, for example, "192.168.1.1"
- 'Proxyhost' => 'http: // www.proxy.com ',
- // Proxy Host Port
- 'Proxyport' => 1234,
- // Whether the proxy needs identity authentication (in HTTP mode)
- 'Proxyauth' => false,
- // Authentication method. select BASIC or NTLM.
- 'Proxyauthtype' => 'basic ',
- // Authentication username and password
- 'Proxyauthuser' => 'user ',
- 'Proxyauthpwd' => 'password ',
- );
- /**
- * Constructor
- *
- * @ Param array $ setopt: refer to private $ setopt to set
- */
- Public function _ construct ($ setopt = array ())
- {
- // Merge user settings and default system settings
- $ This-> setopt = array_merge ($ this-> setopt, $ setopt );
- // Terminate the program if CURL is not installed
- Function_exists ('curl _ init ') | die ('curl Library Not loaded ');
- // Initialization
- $ This-> ch = curl_init ();
- // Set the CURL connection port
- Curl_setopt ($ this-> ch, CURLOPT_PORT, $ this-> setopt ['port']);
- // Use proxy
- If ($ this-> setopt ['proxy']) {
- $ ProxyType = $ this-> setopt ['xytype'] = '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']);
- // The proxy must be authenticated
- 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 "Location:" returned by the server is put in the header and recursively returned to the server.
- Curl_setopt ($ this-> ch, CURLOPT_FOLLOWLOCATION, true );
- // Enable SSL
- If ($ this-> setopt ['SSL ']) {
- // Do not check the certificate source
- Curl_setopt ($ this-> ch, CURLOPT_SSL_VERIFYPEER, false );
- // Check whether the SSL encryption algorithm exists from the certificate
- Curl_setopt ($ this-> ch, CURLOPT_SSL_VERIFYHOST, true );
- }
- // Set the http header to support access from the lighttpd server
- $ Header [] = 'CT :';
- 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 does not wait
- Curl_setopt ($ this-> ch, CURLOPT_CONNECTTIMEOUT, $ this-> setopt ['timeout']);
- // Sets the maximum number of seconds that curl can be executed.
- 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 the COOKIE is used
- If ($ this-> setopt ['usecooker']) {
- // Generate a file for storing temporary cookies (absolute path required)
- $ 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 is output as the data stream (HEADER information). The message is retained here.
- Curl_setopt ($ this-> ch, CURLOPT_HEADER, true );
- // The obtained information 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 the request in GET mode.
- *
- * @ Param string $ url: The requested URL
- * @ Param array $ params: request parameter. Format: array ('id' => 10, 'name' => 'yuanwei ')
- * @ Param array $ referer: reference page. it is automatically set when it is null. if the server has this control, it must be set.
- * @ Return: false: The Returned result is correct.
- */
- Public function get ($ url, $ params = array (), $ referer = '')
- {
- Return $ this-> _ request ('GET', $ url, $ params, array (), $ referer );
- }
- /**
- * Execute the request in POST mode
- *
- * @ Param string $ url: The requested URL
- * @ Param array $ params: request parameter. Format: array ('id' => 10, 'name' => 'yuanwei ')
- * @ Param array $ uploadFile: the uploaded file. it supports relative paths. the format is as follows:
- * Upload a single file: array ('img1' => './file/a.jpg ')
- * Upload multiple files in the same field: array ('IMG '=> array ('./file/a.jpg ','./file/B .jpg '))
- * @ Param array $ referer: reference page, reference page. it is automatically set when it is null. if the server has this control, it must be set.
- * @ Return: false: The Returned result is correct.
- */
- 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 );
- }
- /**
- * Obtain the server information and server Header information before and after the request is sent.
- * [Before]: information set before the request
- * [After]: all server information after the request
- * [Header]: Server Header message
- *
- * @ Return array
- */
- Public function getInfo ()
- {
- Return $ this-> info;
- }
- /**
- * Destructor
- *
- */
- Public function _ destruct ()
- {
- // Disable CURL
- Curl_close ($ this-> ch );
- }
- /**
- * Private method: execute the final request
- *
- * @ Param string $ method: HTTP request method
- * @ Param string $ url: The requested URL
- * @ Param array $ params: request parameter
- * @ Param array $ uploadFile: the uploaded file (effective only when POST is enabled)
- * @ Param array $ referer: Reference Page
- * @ Return: false: The Returned result is correct.
- */
- Private function _ request ($ method, $ url, $ params = array (), $ uploadFile = array (), $ referer = '')
- {
- // If the request is in GET mode, connect to the end of the URL
- If ($ method = 'get '){
- $ Url = $ this-> _ parseUrl ($ url, $ params );
- }
- // Set the request URL
- Curl_setopt ($ this-> ch, CURLOPT_URL, $ url );
- // If it is POST
- If ($ method = 'post '){
- // Send a regular POST request in the type of application/x-www-form-urlencoded
- Curl_setopt ($ this-> ch, CURLOPT_POST, true );
- // Set the POST field value
- $ PostData = $ this-> _ parsmEncode ($ params, false );
- /*
- // If a file is uploaded
- If ($ uploadFile ){
- Foreach ($ uploadFile as $ key => $ file ){
- If (is_array ($ file )){
- $ N = 0;
- Foreach ($ file as $ f ){
- // The 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 );
- }
- // Set the reference page. Otherwise, the page is automatically set.
- If ($ referer ){
- Curl_setopt ($ this-> ch, CURLOPT_REFERER, $ referer );
- } Else {
- Curl_setopt ($ this-> ch, CURLOPT_AUTOREFERER, true );
- }
- // Get all settings
- $ This-> info ['before'] = curl_getinfo ($ this-> ch );
- // Start to execute the request
- $ Result = curl_exec ($ this-> ch );
- // Obtain the packet header
- $ HeaderSize = curl_getinfo ($ this-> ch, CURLINFO_HEADER_SIZE );
- $ This-> info ['head'] = substr ($ result, 0, $ headerSize );
- // Remove the packet header
- $ Result = substr ($ result, $ headerSize );
- // Obtain all information including the information returned by the server
- $ This-> info ['after'] = curl_getinfo ($ this-> ch );
- // If the request is successful
- If ($ this-> errno () = 0) {// & $ this-> info ['after'] ['http _ Code'] = 200
- Return $ result;
- } Else {
- Return false;
- }
- }
- /**
- * Returns the parsed URL, which is used in GET mode.
- *
- * @ Param string $ url: URL
- * @ Param array $ params: the parameter added after the URL
- * @ Return string
- */
- Private function _ parseUrl ($ url, $ params)
- {
- $ FieldStr = $ this-> _ parsmEncode ($ params );
- If ($ fieldStr ){
- $ Url. = strstr ($ url ,'? ') = False? '? ':'&';
- $ Url. = $ fieldStr;
- }
- Return $ url;
- }
- /**
- * ENCODE the parameter
- *
- * @ Param array $ params: parameter
- * @ Param bool $ isRetStr: true: returns false with a string: returns 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;
- }
- }
|