Ver Mensaje Individual
  #2 (permalink)  
Antiguo 15/01/2013, 08:29
Avatar de abimaelrc
abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 14 años, 11 meses
Puntos: 1517
Respuesta: CURL error al descargar CSV

El problema es que tienes código de más y te cuesta entender como funciona. Con esto es suficiente, trátalo, modifícalo a lo que necesites.
Código PHP:
Ver original
  1. <?php
  2. function getPage()
  3. {
  4.     file_put_contents('cookie.txt', '');
  5.     $url    = "http://localhost/c.php";
  6.     $url2   = "http://localhost/d.php";
  7.     $fields = array("usr" => 'usr', "pwd" => 'pwd');
  8.  
  9.     $ch = curl_init();
  10.     curl_setopt($ch, CURLOPT_URL, $url);
  11.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  12.     curl_setopt($ch, CURLOPT_POST, 1);
  13.     curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
  14.     curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
  15.     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
  16.  
  17.     $html = curl_exec($ch);
  18.  
  19.     curl_setopt($ch, CURLOPT_URL, $url2);
  20.     curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
  21.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  22.  
  23.     $html = curl_exec($ch);
  24.  
  25.     echo $html;
  26. }
  27.  
  28. echo getPage();

c.php
Código PHP:
Ver original
  1. <?php
  2.  
  3. if( $_POST['usr'] == 'usr' && $_POST['pwd'] == 'pwd' ){
  4.     $_SESSION['login'] = true;
  5. }

d.php
Código PHP:
Ver original
  1. <?php
  2.  
  3. if( empty($_SESSION['login']) ){
  4.     exit( header('Location: c.php') );
  5. }
  6.  
  7. echo 'algo';
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos