PHP CURL use details

<?php

Class PostCurl Extends AbstractCurl {

/ **

* Call the parent configuration method

* /

public function __construct () {

parent :: __ construct ();

}

/ **

* Implementing the abstract method of the CURL body

*

* @Param Array $ Para

*

* @return void

* /

protected function _CURL ($ para = array ()) {

curl_setopt ($ this -> _ ch, CURLOPT_POST, TRUE);

CURL_SETOPT ($ this -> _ ch, curlopt_postfields, $ para [‘data’]);

}

}

/ **

* CURL abstract class

*

/ **

* CURL Abstract Class

* /

Abstract Class AbstractCurl {

/ **

* CURL resources

* @Var resource

* /

protected $ _CH = null;

/ **

* URL Address

* @Var String

* /

protected $ _URL = ‘;

/ **

* Whether to enable SSL mode

* @var boolean

* /

protected $ _ssl = false;

/ **

* Initialization CURL resources

*

* /

protected function__construct () {

$ this -> _CH = curl_init ();

}

/ * *

* CURL abstract method, processed POST, GET, PUT (not available)

*

* @Param Array $ Para

* /

Abstract protected function _CURL ($ Para = array ());

/ **

* Send Socket Connection

*

* @Param String $ URL

* @Param Array $ Para

* @Param Boolean $ Return

* @Return Mix [Void | String]

* /

private function _socket ($ URL, $ Para, $ RETURN) {

$ this -> _ seturl ($ URL);

/ *

/ *

* Forced to convert to boolean type, not use (Boolean) and settype

* /

if (false === isset ($ Para [‘header’]) {

$ Para [‘Header’] = false;

} else {

$ para [‘header’] = true;

}

curl_setopt ($ this -> _ ch, curlopt_header, $ para [‘header’]);

curl_setopt ($ this -> _ ch, curlopt_timeout, 10);

/ *

* Treatment 302

* /

IF (false === isset ($ Para [‘Location’])) {

$ Para [‘Location ” ] = false;

} else {

$ para [‘location’] = true;

}

CURL_SETOPT ($ this -> _ ch, Curlopt_FollowLocation, $ Para [‘Location ‘]);

Unset ($ Para [‘ Location ‘]);

IF (! EMPTY ($ Para [‘cookiefile’])) {

[153]) {

CURL_SETOPT ($ THIS -> _ CH, CURLOPT_COOKIEFILE, $ Para [‘cookiefile’] [0]);

curl_setopt ($ this -> _ ch, curlopt_cookiejar, $ para [‘cookiefile’] [0]);

}

}

/ *

/ *

* EXEC execution result is saved to the variable

* /

IF ( True === $ RETURN) {

CURL_SETOPT ($ this -> _ ch, curlopt_returnTransfer, true);

}

/ *

* Whether SSL verification is enabled

* /

IF (true === $ this -> _ ssl) {

curl_setopt ($ THIS- > _CH, CURLOPT_SSL_VERIFYHOST, TRUE);

/ *

* Call subclass processing method

* /

$ this -> _ curl ($ para);

$ RESUlt = curl_exec ($ this -> _ ch);

$ apistatus = curl_getinfo ($ this -> _ ch);

IF (ISSET ($ Apistatus) [‘http_code’]) && 200 == $ apistatus [‘http_code’]) {

i (true === $ RETURN) {

curl_close ($ this -> _ ch);

RETURN $ Result;

} elseif (isset ($ apistatus [http_code ‘) && 404 == $ apistatus [‘ http_code ‘]) {

CURL_CLOSE ($ this -> _CH);

} else {

curl_close ($ this -> _ ch);

}

}

/ **

* Initializing URL

*

* @Param string $ URL

*

* @return Boolean [True Success | FALSE Failed]

* /

Private function _SETURL ($ URL) {

$ this -> _ url = $ url;

/ *

* The following code Effective in PHP> 5.3

* /

IF (false! == strstr ($ this -> _ url, ‘https: //’, true) {

$ this -> _ ssl = true;

RETURN CURL_SETOPT ($ this -> _CH, Curlopt_URL, $ THIS -> _ URL);

}

/ ********************************************************* ***** /

/ **

* initiate communication request interface

*

* @ PARAM STRING $ URL

* @Param Array $ Para

* @Param Boolean $ Return

*

* @return string

* /

Final Public Function Socket ($ URL, $ Para = Array (), $ RETURN = true) {

IF (! EMPTY ($ this -> _ ch) {

$ this -> _CH = curl_init ();

}

Return $ this -> _ Socket ($ URL, $ Para, $ Return);

}

}

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment