search
HomePHP LibrariesOther librariesphp-curl-class-masterPHP’s Curl class
php-curl-class-masterPHP’s Curl class
<?php
//curl类
class Curl
{
 function Curl(){
  return true;
 }
 function execute($method, $url, $fields='', $userAgent='', $httpHeaders='', $username='', $password=''){
  $ch = Curl::create();
  if(false === $ch){
   return false;
  }
  if(is_string($url) && strlen($url)){
   $ret = curl_setopt($ch, CURLOPT_URL, $url);
  }else{
   return false;
  }
  //是否显示头部信息
  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);
  }

GET usage:

$curl = new Curl();
$curl->get('http://www.XXX.com/');

POST usage:

$curl = new Curl();
$curl->get('http://www.XXX.com/', 'p=1&time=0');


Disclaimer

All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn

Related Article

[php curl class library] 10 php curl class libraries to download[php curl class library] 10 php curl class libraries to download

21May2017

cURL can use the syntax of a URL to simulate a browser to transfer data. Because it is an analog browser, it supports a variety of protocols, such as FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE and LDAP, etc., including:

curl class encapsulationcurl class encapsulation

08Nov2016

curl class encapsulation code sharing

PHP encapsulated CURL extension class instancePHP encapsulated CURL extension class instance

23Dec2016

This article mainly introduces the PHP encapsulated CURL extension class, and analyzes related techniques such as sending posts, get requests and operating cookies based on curl. It has certain reference value. Friends in need can refer to it.

CURL cache remote file classCURL cache remote file class

09Nov2016

CURL cache remote file code sharing

PHP's powerful CURL POST classPHP's powerful CURL POST class

29Dec2017

This article mainly introduces the powerful PHP POST data submission class in detail. The code is concise and has certain reference value. Interested friends can refer to it. I hope to be helpful.

PHP curl encapsulation class usage example_PHP tutorialPHP curl encapsulation class usage example_PHP tutorial

13Jul2016

Example of using php curl wrapper class. Examples of using the php curl package class. Before using the function, we need to open the php curl module (libeay32.dll, ssleay32.dll, php5ts.dll, php_curl.dll). Steps to open the php curl function library 1). Remove

See all articles