title: Reusing cookie in curl not working
body: <p>first time here, and I need help, please!</p>
  
  <p>I have two functions that do different things. The first, only do a login in an external website, and its working fine. In the second fuction, I need to do a <strong>POST</strong> with the login saved from the first. I use the <strong>CURLOPT_COOKIEJAR</strong> and <strong>CURLOPT_COOKIEFILE</strong> with the same path in both functions, but when I print what I'm sending in each function with <strong>var_dump(curl_getinfo($ch))</strong>, the cookie only shows in the first one, and not in the second, causing a <strong>401 Unauthorized Server</strong> as a result of the second function.</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;?php
  
  $cookie_path = dirname(__FILE__).'/cookie.txt';
  
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $login_conf['login_url']);
  curl_setopt($ch, CURLOPT_REFERER, $login_conf['referer_header']);
  curl_setopt($ch, CURLOPT_POST, 1 );
  curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_HEADER, TRUE );
  curl_setopt($ch, CURLINFO_HEADER_OUT, true);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_path);
  curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_path);
  
  $html = curl_exec($ch);
  ?&gt;
  </code></pre>
  
  <p>Thats basically the content of the login function, and this:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;?php
  
  $cookie_path = dirname(__FILE__).'/cookie.txt';
  
  $ch2 = curl_init();
  curl_setopt($ch2, CURLOPT_URL, $purge_conf['request_url']);
  curl_setopt($ch2, CURLOPT_REFERER, $refheader_submit);
  curl_setopt($ch2, CURLOPT_POST, 1 );
  curl_setopt($ch2, CURLOPT_POSTFIELDS, $query_purge);
  curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch2, CURLOPT_HEADER, TRUE );
  curl_setopt($ch2, CURLOPT_HTTPHEADER, array(
      'Content-Type: application/json',
      'Content-Length: '.strlen($query_purge))
  );
  curl_setopt($ch2, CURLINFO_HEADER_OUT, true);
  curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false); 
  curl_setopt($ch2, CURLOPT_SSL_VERIFYHOST, false);
  curl_setopt($ch2, CURLOPT_COOKIEJAR, $cookie_path);
  curl_setopt($ch2, CURLOPT_COOKIEFILE, $cookie_path);
  
  $html_purge = curl_exec($ch2);
  ?&gt;
  </code></pre>
  
  <p>Is the other one, that I need to sent a json post to other page, for witch I need to keep the login and cookie.</p>
  
  <p>I dont know if I am doing something wrong, or if I am missing something.</p>