- /**
- * Curl Package Class
- * by bbs.it-home.org
- */
- Class Curl_class
- {
- function Curl_class ()
- {
- return true;
- }
- function Execute ($method, $url, $fields = ', $userAgent = ', $httpHeaders = ', $username = ', $password = ')
- {
- $ch = Curl_class::create ();
- if (false = = = $ch)
- {
- return false;
- }
- if (is_string ($url) && strlen ($url))
- {
- $ret = curl_setopt ($ch, Curlopt_url, $url);
- }
- Else
- {
- return false;
- }
- Whether to display header information
- curl_setopt ($ch, Curlopt_header, false);
- //
- curl_setopt ($ch, Curlopt_returntransfer, true);
- if ($username! = ")
- {
- curl_setopt ($ch, Curlopt_userpwd, $username. ':' . $password);
- }
- $method = Strtolower ($method);
- if (' post ' = = $method)
- {
- curl_setopt ($ch, Curlopt_post, true);
- if (Is_array ($fields))
- {
- $sets = Array ();
- foreach ($fields as $key = $val)
- {
- $sets [] = $key. '=' . UrlEncode ($val);
- }
- $fields = Implode (' & ', $sets);
- }
- curl_setopt ($ch, Curlopt_postfields, $fields);
- }
- else if (' put ' = = $method)
- {
- curl_setopt ($ch, Curlopt_put, true);
- }
- curl_setopt ($ch, curlopt_progress, true);
- curl_setopt ($ch, Curlopt_verbose, true);
- curl_setopt ($ch, Curlopt_mute, false);
- curl_setopt ($ch, Curlopt_timeout, 3);//sets the curl timeout in seconds, for example, post the message 3 seconds after the automatic end of the run.
- if (strlen ($userAgent))
- {
- curl_setopt ($ch, curlopt_useragent, $userAgent);
- }
- if (Is_array ($httpHeaders))
- {//bbs.it-home.org
- curl_setopt ($ch, Curlopt_httpheader, $httpHeaders);
- }
- $ret = curl_exec ($ch);
- if (Curl_errno ($ch))
- {
- Curl_close ($ch);
- Return Array (Curl_error ($ch), Curl_errno ($ch));
- }
- Else
- {
- Curl_close ($ch);
- if (!is_string ($ret) | |!strlen ($RET))
- {
- return false;
- }
- return $ret;
- }
- }
- Function post ($url, $fields, $userAgent = ', $httpHeaders = ', $username = ', $password = ')
- {
- $ret = Curl_class::execute (' POST ', $url, $fields, $userAgent, $httpHeaders, $username, $password);
- if (false = = = $ret)
- {
- return false;
- }
- if (Is_array ($ret))
- {
- return false;
- }
- return $ret;
- }
- function Get ($url, $userAgent = ', $httpHeaders = ', $username = ', $password = ')
- {
- $ret = Curl_class::execute (' GET ', $url, ', $userAgent, $httpHeaders, $username, $password);
- if (false = = = $ret)
- {
- return false;
- }
- if (Is_array ($ret))
- {
- return false;
- }
- return $ret;
- }
- function Create ()
- {
- $ch = null;
- if (!function_exists (' Curl_init '))
- {
- return false;
- }
- $ch = Curl_init ();
- if (!is_resource ($ch))
- {
- return false;
- }
- return $ch;
- }
- }
Copy Code |