title: PHP Form POST to external URL with Redirect to another URL
body: <p>So, what I am trying to accomplish is have a self-posting PHP form, POST to an external page (using CURL) which in turn redirects to another page.  Currently, what is happening is that once I click "Submit" on the form (in contact.php) it will POST to itself (as it is a self-posting form).  The script then prepares the POST using CURL and performs the post.  The external page does its processing and then, the external page is supposed to redirect back to another page, in a referring domain.  However, what happens instead, is that it seems like the contact.php page loads the HTML from the page the external page redirected to, and then, the contact.php's HTML loads after that, ON THE SAME PAGE.</p>
  
  <p>The effect, is what looks like two separate pages rendered as one page.  Naturally, I just want to perform the POST and have the browser render the page it is supposed to redirect to as specified by the external page. </p>
  
  <p>Here is the code I have so far:</p>
  
  <pre><code>&lt;?php     
  if(isset($_POST['submit']))
   {
    doCURLPost();
   }
  
   function doCURLPost()
   { 
    $emailid = "2, 4";
  
    $hotel = $_POST['hotel'];
  
  
    //you will need to setup an array of fields to post with
    //then create the post string
  
    $data = array ( "recipient" =&gt; $emailid,
        "subject" =&gt; "Hotel Contact Form",
        "redirect" =&gt; "http://www.localhost.com/thanx.htm",
        "Will be staying in hotel: " =&gt; $_POST['hotel'],
        "Name" =&gt; $_POST['Name'],
        "Phone" =&gt; $_POST['Phone'],
        "Comments" =&gt; $_POST['Comments']);
  
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://www.externallink.com/external.aspx");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_POST, true);  
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Referer: http://www.localhost.com/contact.php"));
    $output = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);
   }
  ?&gt;
  </code></pre>