Foros del Web » Programando para Internet » PHP »

Ayud CurlPhp5

Estas en el tema de Ayud CurlPhp5 en el foro de PHP en Foros del Web. Hola tengo un error creo que el codigo esta bien pero me da este error: Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is ...
  #1 (permalink)  
Antiguo 28/04/2011, 09:37
Avatar de BapeMilo  
Fecha de Ingreso: octubre-2010
Mensajes: 71
Antigüedad: 13 años, 6 meses
Puntos: 1
Ayud CurlPhp5

Hola tengo un error creo que el codigo esta bien
pero me da este error: Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/unlim219/public_html/a/curl.php on line 93

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/unlim219/public_html/a/curl.php on line 93

Código PHP:
Ver original
  1. <?php
  2. /*******************************************************************************
  3.  *                      CURL Class
  4.  *******************************************************************************
  5.  *      Author:     Vikas Patial
  6.  *      Email:      [email protected]
  7.  *      Website:    http://www.ngcoders.com
  8.  *
  9.  *      File:       curl.php
  10.  *      Version:    1.0.0
  11.  *      Copyright:  (c) 2008 - Vikas Patial
  12.  *                  You are free to use, distribute, and modify this software
  13.  *                  under the terms of the GNU General Public License.  See the
  14.  *                  included license.txt file.
  15.  *
  16.  *******************************************************************************
  17.  *  VERION HISTORY:
  18.  *
  19.  *      v1.1.0 [1.1.2010]  - Streaming and getSize Added
  20.  *      v1.0.0 [18.9.2008] - Initial Version
  21.  *
  22.  *******************************************************************************
  23.  *  DESCRIPTION:
  24.  *
  25.  *      NOTE: See www.ngcoders.com for the most recent version of this script
  26.  *      and its usage.
  27.  *
  28.  *******************************************************************************
  29. */
  30.  
  31. class Curl {
  32.     var $callback = false;
  33.     var $secure = false;
  34.     var $conn = false;
  35.     var $cookiefile =false;
  36.     var $header = false;
  37.     var $cookie = false;
  38.     var $follow = true;
  39.         var $dump   = false;
  40.         var $range  = false;
  41.         var $timeout = false;
  42.     var $user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
  43.  
  44.     function Curl($u = false) {
  45.         $this->conn = curl_init();
  46.         if (!$u) {
  47.             $u = rand(0,100000);
  48.         }
  49.  
  50.                 $file = dirname(__FILE__).'/temp/'.md5($u);
  51.                 $file = str_replace('\\','/', $file);
  52.         $this->cookiefile= $file;
  53.  
  54.     }
  55.  
  56.     function setCallback($func_name) {
  57.         $this->callback = $func_name;
  58.     }
  59.  
  60.     function close() {
  61.         curl_close($this->conn);
  62.         if (is_file($this->cookiefile)) {
  63.             //unlink($this->cookiefile);
  64.         }
  65.  
  66.     }
  67.  
  68.     function doRequest($method, $url, $vars) {
  69.  
  70.         $ch = $this->conn;
  71.  
  72.         curl_setopt($ch, CURLOPT_URL, $url);
  73.         if ($this->header) {
  74.             curl_setopt($ch, CURLOPT_HEADER, 1);
  75.         } else {
  76.             curl_setopt($ch, CURLOPT_HEADER, 0);
  77.         }
  78.         curl_setopt($ch, CURLOPT_USERAGENT,$this->user_agent);
  79.                 curl_setopt( $ch, CURLOPT_HTTPHEADER, array("REMOTE_ADDR: ".$_SERVER['REMOTE_ADDR'], "HTTP_X_FORWARDED_FOR: ".$_SERVER['REMOTE_ADDR'])); // send users ip ???
  80.  
  81.  
  82.         if($this->secure) {
  83.             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  0);
  84.             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  85.         }
  86.  
  87.         if ($this->cookie)
  88.         {
  89.             curl_setopt($ch, CURLOPT_COOKIE,$this->cookie);
  90.         }
  91.  
  92.         if ($this->follow) {
  93.             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  94.         } else {
  95.             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
  96.         }
  97.  
  98.         if($this->dump) {
  99.             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
  100.         } else {
  101.             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  102.         }
  103.  
  104.         if($this->range)
  105.         {
  106.             curl_setopt($ch, CURLOPT_RANGE,$this->range);
  107.         }
  108.  
  109.         if($this->timeout)
  110.         {
  111.             curl_setopt($ch, CURLOPT_TIMEOUT,$this->timeout);
  112.         } else {
  113.             curl_setopt($ch, CURLOPT_TIMEOUT,false);
  114.         }
  115.  
  116.         curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookiefile);
  117.         curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookiefile);
  118.  
  119.         if ($method == 'POST') {
  120.                 curl_setopt($ch, CURLOPT_POST, 1);
  121.                 curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
  122.                 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect: ')); // lighttpd fix
  123.         }
  124.  
  125.         $data = curl_exec($ch);
  126.  
  127.         if ($data) {
  128.                 if ($this->callback)
  129.                 {
  130.                         $callback = $this->callback;
  131.                         $this->callback = false;
  132.                         return call_user_func($callback, $data);
  133.                 } else {
  134.                         return $data;
  135.                 }
  136.         } else {
  137.                 return false;
  138.         }
  139.     }
  140.  
  141.     function get($url) {
  142.         return $this->doRequest('GET', $url, 'NULL');
  143.     }
  144.  
  145.  
  146.         function processHeader($ch,$string)
  147.         {
  148.             if(preg_match('%Content-Range: bytes 0-1024/([0-9]+)%', $string,$match))
  149.             {
  150.                 $this->size =  $match[1];
  151.                 return false;
  152.             }
  153.  
  154.             if(preg_match('%Content-Length: ([0-9]+)%', $string,$match))
  155.             {
  156.                 $this->size =  $match[1];
  157.                 return false;
  158.             }
  159.  
  160.             return strlen($string);
  161.         }
  162.  
  163.         function getSize($url) {
  164.  
  165.             $this->size = false;
  166.  
  167.             $this->header  =  true;
  168.             $this->range   = "0-1024";
  169.             $this->dump    =  true; // some sites dont echo in curl
  170.  
  171.             curl_setopt($this->conn,CURLOPT_HEADERFUNCTION,array($this,processHeader));
  172.             ob_start();
  173.             $this->doRequest('GET', $url,false);
  174.             $result = ob_get_contents();
  175.             ob_end_clean();
  176.  
  177.             $this->dump    = false;
  178.             $this->header  = false;
  179.             $this->range   = false;
  180.          
  181.             return $this->size;
  182.     }
  183.  
  184.  
  185.     function getError()
  186.     {
  187.         return curl_error($ch);
  188.     }
  189.  
  190.     function post($url, $params = false) {
  191.  
  192.         $post_data = '';
  193.  
  194.         if (is_array($params)) {
  195.  
  196.             foreach($params as $var=>$val) {
  197.                 if(!empty($post_data))$post_data.='&';
  198.                 $post_data.= $var.'='.urlencode($val);
  199.             }
  200.  
  201.         } else {
  202.             $post_data = $params;
  203.         }
  204.  
  205.         return $this->doRequest('POST', $url, $post_data);
  206.     }
  207.        
  208.         function streamHeader($ch,$string)
  209.         {
  210.             if(empty ($string)) return;
  211.  
  212.             header($string);
  213.             return strlen($string);
  214.         }
  215.  
  216.         function stream($url)
  217.         {
  218.             $this->dump = true;
  219.             curl_setopt($this->conn,CURLOPT_HEADERFUNCTION,array($this,streamHeader));
  220.             $this->doRequest('GET', $url,false);
  221.  
  222.         }
  223.  
  224.         function getRedirect($url)
  225.     {
  226.         $this->follow = false;
  227.         $this->header = true;
  228.  
  229.         $html =  $this->get($url);
  230.  
  231.         if(preg_match('/Location: (.*?)[\r\n]+/',$html,$match) || preg_match('/http-equiv=\'Refresh\' content=\'[0-9]+;url=(.*?)\'/s',$html,$match))
  232.         {
  233.             return $match[1];
  234.         }
  235.  
  236.         $this->follow = true;
  237.         $this->header = false;
  238.     }
  239.        
  240. }
  241.  
  242. function getPage($url,$post = false,$cookie = false)
  243. {
  244.     $pURL = parse_url($url);
  245.  
  246.     $curl = new Curl($pURL['host']);
  247.  
  248.     if (strstr($url,'https://'))
  249.     {
  250.         $curl->secure = true;
  251.     }
  252.  
  253.     if ($post) {
  254.         return $curl->post($url,$post);
  255.     } else {
  256.         return $curl->get($url);
  257.     }
  258.  
  259. }
  #2 (permalink)  
Antiguo 28/04/2011, 10:07
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 14 años, 10 meses
Puntos: 1517
Respuesta: Ayud CurlPhp5

El mensaje es bastante claro, ¿tienes activado en tu servidor safe_mode?
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos
  #3 (permalink)  
Antiguo 28/04/2011, 10:26
Avatar de BapeMilo  
Fecha de Ingreso: octubre-2010
Mensajes: 71
Antigüedad: 13 años, 6 meses
Puntos: 1
Respuesta: Ayud CurlPhp5

safe mode esta off
  #4 (permalink)  
Antiguo 01/05/2011, 08:06
Avatar de BapeMilo  
Fecha de Ingreso: octubre-2010
Mensajes: 71
Antigüedad: 13 años, 6 meses
Puntos: 1
Respuesta: Ayud CurlPhp5

La linea de error es esta esta todo bien pero me sige tirando error
Código PHP:
Ver original
  1. if ($this->follow) {
  2.             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  3.         } else {
  4.             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
  5.         }
  #5 (permalink)  
Antiguo 01/05/2011, 08:25
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 14 años, 10 meses
Puntos: 1517
Respuesta: Ayud CurlPhp5

Pues lo otro que indica es que debes tener open_basedir indicando algún directorio y eso te limita.
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos

Etiquetas: Ninguno
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 12:37.