title: Use CURL in PHP to POST Login to a Remote auth function/php file
body: <p>I am trying to make a Login system for my script and am stuck at a point.</p>
  
  <p>What I need to do is POST the login details of user he has submitted on login.php (server1) to my backend script's login system verify.php(server2)
  The verify.php uses the POST data to validate the login information and actually set cookie and all other things for the backend system.</p>
  
  <p>I am using a 3rd part script on server2 so I cant modify much in it, the whole login thing works if I directly do a HTML FORM POST from server1 to directly server2 (using action=verify.php link)</p>
  
  <p>But for various reasons and security purposes aswell as executing additional code, I need to use curl or some other way to POST the login.</p>
  
  <p>My login system is working as I can echo the status that login info is correct and login function worked on server2 in my logs, but for some reason (probably due to curl) the cookie isnt getting set/saved to user's PC and so when he visits the server2 url, he still sees "Login Required" error message I have set and therefore isnt getting autologgedin via that login.php file.</p>
  
  <p>This is my login.php code (server1) and $hostname is link to server2 (verify.php)</p>
  
  <pre><code>$data['username']=$username;
  $data['pass']=$pass;
  
  //open connection
      $ch = curl_init();
  
      //set the url, number of POST vars, POST data
      curl_setopt($ch,CURLOPT_URL, $hostname);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  
      curl_setopt($ch,CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
      curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($ch,CURLOPT_PROXY, $proxy);
      curl_setopt($ch,CURLOPT_COOKIEJAR, "cookie.txt");
      curl_setopt($ch,CURLOPT_COOKIEFILE, "cookie.txt");
  //curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
      //execute post
      $result = curl_exec($ch);
  
      print_r(curl_error($ch));
      print_r(curl_getinfo($ch));
      print_r(curl_errno($ch));
  
      //close connection
      curl_close($ch);
  </code></pre>
  
  <p>This is the curl response</p>
  
  <pre><code>Trying to login with *user* and *pass* Var check username password
   SuccessArray ( [url] =&gt; *hostname* [content_type] =&gt; text/html [http_code] =&gt; 200 [header_size] =&gt; 712 [request_size] =&gt; 308 [filetime] =&gt; -1 [ssl_verify_result] =&gt; 0 [redirect_count] =&gt; 0 [total_time] =&gt; 0.245843 
  [namelookup_time] =&gt; 0.010171 [connect_time] =&gt; 0.01039 [pretransfer_time] =&gt; 0.010398 [size_upload] =&gt; 257 [size_download] =&gt; 93 [speed_download] =&gt; 378 [speed_upload] =&gt; 1045 [download_content_length] =&gt; -1 [upload_content_length] =&gt; 257 [starttransfer_time] =&gt; 
  0.042541 [redirect_time] =&gt; 0 [certinfo] =&gt; Array ( ) [redirect_url] =&gt; ) 0
  </code></pre>
  
  <p>PS: Its not a remote login system for php use, its a system for user login instead of directly using HTML FORM action</p>
  
  <p>Any help would be appreciated</p>