title: with php, how can I send data via POST simulating in full a form submit?
body: <p>My problem is this: I have an online service which hosts my customer's catalogue.<br>
  This service requires authentication, but I have one single username/pwd.<br>
  My customer, instead, wants to manage separately every single user with their own user/pwd and access statistics. So what I did was to build my own account management, so far so good.<br>
  What I need to do now is to add a login form which users should fill in with their own credentials; once sent, the script should proceed with the authentication and, if everything's ok, increment the access count, send the remote system's login data via POST and redirect the browser to the response page, exaclty the same way as a normal form would do.<br>
  I tried using <code>curl</code> this way:</p>
  
  <pre><code>if (authenticate($_POST['usr'],$_POST['pwd'])) {
      $url = "http://www.foo.com/login.php";
      $postdata = http_build_query(array('username'=&gt;"foo",'password'=&gt;"bar"));
      $curl = curl_init();
      curl_setopt($curl, CURLOPT_URL, $url);
      curl_setopt($curl, CURLOPT_POST, 1);
      curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
      curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
      curl_exec($curl);
      curl_close($curl);
  }
  </code></pre>
  
  <p>but I end up loading the destination page's data into my own page, instead of being redirected to the site.<br>
  What should I do?<br>
  P.S. I would avoid resorting to an hidden form submitted via JS, if possible.<br>
  Thanks!</p>