title: PHP/CURL - Making a POST request to another page and following the URL
body: <p>I am going to try and explain this as best I can, I hope that I make sense as English is not my first language.</p>
  
  <p>Lets say that I have a form on page 1 which contains these 3 inputs:</p>
  
  <pre><code>$_POST["name"];
  $_POST["amount"];
  $_POST["email"];
  </code></pre>
  
  <p>And on a second page process.php I also have another input:</p>
  
  <pre><code>$_POST["message"];
  </code></pre>
  
  <p>And finally on an external website there is a form that I want to POST to without having to type anything into their system:</p>
  
  <pre><code>&lt;form action="display.php" method="post"&gt;
   &lt;input type="text" name="name"&gt;&lt;br&gt;
   &lt;input type="text" name="amount"&gt;&lt;br&gt;
   &lt;input type="text" name="email"&gt;&lt;br&gt;
   &lt;input type="text" name="message"&gt;&lt;br&gt;
  &lt;input type="submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I then want to be able to be automatically redirected to www.example.com/display.php <strong>from my process.php page and submit the form automatically</strong> and be able to see all of my information that I just entered</p>
  
  <p>Example of what display.php looks like:</p>
  
  <p><a href="https://i.stack.imgur.com/S7JRD.png" rel="nofollow noreferrer">Display.php</a></p>
  
  <p>I do not have access to the code on the external website or display.php so this means that I cannot edit the code or use any sessions.</p>
  
  <p><strong>I hope that you understand me and that you could be able to help me, I would be so grateful if you could help me!</strong></p>
  
  <p>EDIT:</p>
  
  <p>I tested some code that I was given in an answer and looks promising but it didn't pass the POST data to the external page (Which is not external for testing purposes)</p>
  
  <p>Here is the code used to test below:</p>
  
  <p>process.php</p>
  
  <pre><code>&lt;?php
  $_POST["name"] = "name";
  $_POST["amount"] = "amount";
  $_POST["email"] = "email";
  $_POST["message"] = "message";
  
  $post = array();
  $post[] = "name=" . $_POST["name"];
  $post[] = "amount=" . $_POST["amount"];
  $post[] = "email=" . $_POST["email"];
  $post[] = "message=" . $_POST["message"];
  
  $ch = curl_init('http://localhost/display');
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  header('Content-Type: text/html');
  echo curl_exec($ch);
  ?&gt;
  </code></pre>
  
  <p>display.php</p>
  
  <pre><code>&lt;?php
  echo $_POST["name"];
  echo $_POST["amount"];
  echo $_POST["email"];
  echo $_POST["message"];
  ?&gt;
  </code></pre>
  
  <p>But for some reason this did not work?</p>