In the afternoon, I saw a space becoming popular. My friends have been in touch for a long time! Contact me! Whoever sees it in your own space will have their QQ and nickname displayed on the picture! How is this done? I wrote a small demo here. To get a QQ nickname, you need to visit a web page. I have the original class here! Just use it directly, there are many ways to get it! But let’s go straight to 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 set or returned by the server before and after CURL execution
- private $info = array();
- //CURL SETOPT information
- private $setopt = array(
- //The accessed port, http default is 80
- 'port'=>80,
- //Client USERAGENT, such as: "Mozilla/4.0", if it is empty Use the user's browser
- 'userAgent'=>'',
- //Connection timeout period
- 'timeOut'=>30,
- //Whether to use COOKIE is recommended to be turned on, because most websites will use it
- 'useCookie'= >true,
- //Whether to support SSL
- 'ssl'=>false,
- //Whether the client supports gzip compression
- 'gzip'=>true,
-
- //Whether to use a proxy
- 'proxy'=> ;false,
- //Proxy type, you can choose HTTP or SOCKS5
- 'proxyType'=>'HTTP',
- //The host address of the proxy, if it is HTTP mode, it should be written in the URL format, such as: "http://www .proxy.com"
- //SOCKS5 method directly writes the host domain name in the form of IP, such as: "192.168.1.1"
- 'proxyHost'=>'http://www.proxy.com',
- //Proxy The port of the host
- 'proxyPort'=>1234,
- //Whether the proxy requires identity authentication (in HTTP mode)
- 'proxyAuth'=>false,
- //Authentication method. You can choose BASIC or NTLM method
- 'proxyAuthType '=>'BASIC',
- //Authenticated username and password
- 'proxyAuthUser'=>'user',
- 'proxyAuthPwd'=>'password',
- );
-
- /**
- * Constructor
- *
- * @param array $setopt: Please refer to private $setopt to set
- * /
- public function __construct($setopt=array())
- {
- //Merge user settings and system default settings
- $this->setopt = array_merge($this->setopt,$setopt);
- / /If CURL is not installed, terminate the program
- 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['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']);
- //The proxy needs to 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 will be returned Put it in the header and return it to the server recursively
- curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
- //Open support for SSL
- if($this->setopt['ssl']){
- // No check on the source of the authentication certificate
- 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 http header to support access to lighttpd server
- $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 waiting time, 0 does not wait
- curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, $this->setopt['timeOut']);
- //Set the maximum number of seconds 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 COOKIE is used? if($this->setopt['useCookie']){
- //Generate a file to store temporary COOKIE (must be absolute path)
- $cookfile = tempnam(sys_get_temp_dir(),'cuk');
- //After the connection is closed, store cookie information
- curl_setopt($this->ch, CURLOPT_COOKIEJAR, $cookfile);
- curl_setopt($this-> ;ch, CURLOPT_COOKIEFILE, $cookfile);
- }
- //Whether to output the header file information as a data stream (HEADER information), retain the message here
- curl_setopt($this->ch, CURLOPT_HEADER, true);
- / /The obtained information is returned in the form of a file stream instead of being output directly.
- curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true) ;
- curl_setopt($this->ch, CURLOPT_BINARYTRANSFER, true) ;
- }
-
- /**
- * Execute the request in GET mode
- *
- * @param string $url: the URL of the request
- * @param array $params: the parameters of the request, the format is like: array('id'=>10,'name'=> ;'yuanwei')
- * @param array $referer: Reference page, automatically set when empty. If the server has control over this, it must be set.
- * @return Error return: false Correct return: result content
- */
- 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 URL of the request
- * @param array $params: the parameters of the request, the format is like: array('id'=>10,'name'=> ;'yuanwei')
- * @param array $uploadFile: The uploaded file supports relative paths and the format is as follows
- * Single file upload: array('img1'=>'./file/a.jpg')
- * Same as Field multiple file upload: array('img'=>array('./file/a.jpg','./file/b.jpg'))
- * @param array $referer: reference page, reference page , automatically set when empty. If the server has control over this, it must be set.
- * @return Error return: false Correct return: 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 error code
- *
- * @return int
- */
- public function errno()
- {
- return curl_errno($this->ch);
- }
-
- /**
- * Get all the server information and server header information before and after sending the request, where
- * [before]: the information set before the request
- * [after]: all the server information after the request
- * [header]: server Header message information
- *
- * @return array
- */
- public function getInfo()
- {
- return $this->info;
- }
-
- /**
- * Destructor
- *
- */
- public function __destruct()
- {
- //关闭CURL
- curl_close($this->ch);
- }
-
- /**
- * Private method: Execute the final request
- *
- * @param string $method: HTTP request method
- * @param string $url: Requested URL
- * @param array $params: Requested parameters
- * @param array $uploadFile :Uploaded file (valid only when POST)
- * @param array $referer: Reference page
- * @return Error return: false Correct return: result content
- */
- private function _request($method, $url, $params=array(), $uploadFile=array(), $referer='')
- {
- //如果是以GET方式请求则要连接到URL后面
- if($method == 'GET'){
- $url = $this->_parseUrl($url,$params);
- }
- //设置请求的URL
- curl_setopt($this->ch, CURLOPT_URL, $url);
- //如果是POST
- if($method == 'POST'){
- //发送一个常规的POST请求,类型为:application/x-www-form-urlencoded
- curl_setopt($this->ch, CURLOPT_POST, true) ;
- //设置POST字段值
- $postData = $this->_parsmEncode($params,false);
- /*
- //如果有上传文件
- if($uploadFile){
- foreach($uploadFile as $key=>$file){
- if(is_array($file)){
- $n = 0;
- foreach($file as $f){
- //文件必需是绝对路径
- $postData[$key.'['.$n++.']'] = '@'.realpath($f);
- }
- }else{
- $postData[$key] = '@'.realpath($file);
- }
- }
- }
- */
- //pr($postData); die;
- curl_setopt($this->ch, CURLOPT_POSTFIELDS, $postData);
- }
- //设置了引用页,否则自动设置
- if($referer){
- curl_setopt($this->ch, CURLOPT_REFERER, $referer);
- }else{
- curl_setopt($this->ch, CURLOPT_AUTOREFERER, true);
- }
- //得到所有设置的信息
- $this->info['before'] = curl_getinfo($this->ch);
- //开始执行请求
- $result = curl_exec($this->ch);
- //得到报文头
- $headerSize = curl_getinfo($this->ch, CURLINFO_HEADER_SIZE);
- $this->info['header'] = substr($result, 0, $headerSize);
- //去掉报文头
- $result = substr($result, $headerSize);
- //得到所有包括服务器返回的信息
- $this->info['after'] = curl_getinfo($this->ch);
- //如果请求成功
- if($this->errno() == 0){ //&& $this->info['after']['http_code'] == 200
- return $result;
- }else{
- return false;
- }
-
- }
-
- /**
- * Returns the parsed URL, which will be used in GET mode
- *
- * @param string $url:URL
- * @param array $params: Parameters 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 encode the parameters
- *
- * @param array $params: parameters
- * @param bool $isRetStr: true: return as string false: return as 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;
- }
- }
复制代码
|