Last active
August 29, 2015 13:56
-
-
Save luiscelismx/9280963 to your computer and use it in GitHub Desktop.
Función en PHP para enviar por cURL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| -- ============================================= | |
| -- Author: Luis Antonio Celis Molina | |
| -- Create date: 20/06/2013 | |
| -- Description: Función para enviar mediante la libreria cURL | |
| -- Parametros: @param url Url de envio | |
| -- @param postfields Array o query string con las variables a enviar | |
| -- @urlencoded Enviar url encoded | |
| -- @port Puerto de transmisión | |
| -- ============================================= | |
| */ | |
| function send_curl($url,$postfields,$urlencoded=true,$port=NULL,$autenificar=NULL) { | |
| if(!function_exists('curl_init')) { | |
| return false; | |
| }else{ | |
| // Modificar el formato del array | |
| // postfields a string | |
| if($urlencoded==true){ | |
| if(is_array($postfields)){ | |
| $pf=http_build_query($postfields); | |
| $postfields=$pf; | |
| } | |
| } | |
| //Attempt HTTPS connection | |
| $ch = curl_init(); | |
| curl_setopt($ch, CURLOPT_URL, $url); | |
| if(!empty($autenificar)) | |
| curl_setopt($ch, CURLOPT_USERPWD, $autenificar); | |
| curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; WINDOWS; .NET CLR 1.1.4322)'); | |
| curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Charset'=>'utf-8,*')); | |
| curl_setopt($ch, CURLOPT_MAXREDIRS, 10); | |
| curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); | |
| curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
| curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); | |
| curl_setopt($ch, CURLOPT_TIMEOUT, 30); | |
| curl_setopt($ch, CURLOPT_HEADER, 0); | |
| curl_setopt($ch, CURLOPT_POST, 1); | |
| curl_setopt($ch, CURLOPT_VERBOSE, 1); // Debug | |
| // -- Cookies | |
| curl_setopt($ch, CURLOPT_COOKIESESSION, 1); | |
| curl_setopt($ch, CURLOPT_COOKIEFILE, "httpsdocs/tmp/"); | |
| curl_setopt($ch, CURLOPT_COOKIEJAR, "httpsdocs/tmp/"); | |
| curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); | |
| if(!empty($port)) curl_setopt($ch, CURLOPT_PORT, $port); | |
| if (defined('CURLOPT_ENCODING')) curl_setopt($ch, CURLOPT_ENCODING, ""); | |
| $res=curl_exec ($ch); | |
| if($res==null){ | |
| return false; | |
| } | |
| if (!defined('CURLOPT_ENCODING')) { | |
| return false; | |
| } | |
| curl_close ($ch); | |
| } | |
| return $res; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment