title: PHP cURL cookies & keeping session open
body: <p>I'm having some trouble with cURL (using PHP). Bascially I want to login and perform some functions on a website. This would usually be fine, however the website generates a unique URL for the login page AND a dynamic/unique POST url each time the login page is accessed that must be used during that session.</p>
  
  <p>Therefore - I am currently navigating to the login page, then scraping the page to retrieve the unique POST url (I'm successful doing that) and then formulating a POST request and dispatching that to the unique URL. It's not working though and I think the problem is either to do with cookies or the fact I'm not keeping the session open...</p>
  
  <p>Firstly, I don't know why cookies aren't being saved (however they are only for that browser session, maybe that could be the reason?).. I've created a test page which stores a cookie and that works.. so maybe it's not my problem.</p>
  
  <p>Secondly, I don't think I'm keeping the session open. I'm calling:</p>
  
  <p><code>$curl = curl_init();</code> then grabbing the unique POST url, then calling <code>$ch = curl_init($loginPostUrl);</code> to initialise my POST request and finally after it's all complete            </p>
  
  <pre><code>curl_close($ch);
  curl_close($curl);
  </code></pre>
  
  <p>However, I don't think this is keeping the initial session open whilst making post request (therefore the POST url I retrieved is invalid..)</p>
  
  <p>Could someone please explain how to do these requests in the same session?</p>
  
  <p>Sorry - my explanation is poor, I'll try and clarify if people don't understand.</p>
  
  <p>Many thanks :)</p>