title: Login with cURL and Save Sessions
body: <p>index.php</p>
  
  <pre><code>&lt;?php
  if($_POST) {
      $url = 'http://127.0.0.1/login.php';
      $socks = '127.0.0.1:9999';
      $fields = 'password=' . $_POST['captcha'] . '';
  
      $ch = curl_init();
  
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22");
      //curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
      //curl_setopt($ch, CURLOPT_PROXY, $socks);
      //curl_setopt($ch, CURLOPT_INTERFACE, 'eth0:12');
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
      curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
      curl_setopt($ch, CURLOPT_POST, true);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
      curl_setopt($ch, CURLOPT_TIMEOUT, 3600);
  
      $result = curl_exec($ch);
  
      curl_close($ch);
  }
  ?&gt;
  &lt;form action="" method="POST"&gt;
      Password &lt;input type="text" name="password" value="" /&gt;
      &lt;input type="submit" value="Login" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>login.php</p>
  
  <pre><code>&lt;?php
  session_start();
  
  $_SESSION["TestSession"] = 1;
  setcookie("TestCookie", 1, time() + 3600);
  
  if($_POST) {
      file_put_contents("login.txt", serialize($_POST));
  }
  
  echo 'OK';
  ?&gt;
  </code></pre>
  
  <p>After I run index.php and submit the form with my password, it's being saved to <code>login.txt</code> but in <code>cookie.txt</code> I don't have <code>TestCookie</code> or <code>TestSession</code> saved.</p>
  
  <p>I'll be thankful for any help, as I really don't understand where the problem is.</p>