Execute a PHP POST within a PHP script

Hello guys,

I have googled info about this but I always see a different solution. And there are always people commenting that the solution is not correct. Here is the problem:

I have a script called “script1.php” and I would like to send data to another script called “script2.php” using the POST method. But I’m NOT sending the data with a form. Please take a look at the example code below of script1.php. Any one know how I can do this?


<?php
// script1.php
if (isset($_POST['submit']))
   {
   // check to see if data is valid
   if (....) {echo "Data is NOT valid";}
   // data is valid, send data to SCRIPT2.PHP with POST and run script2.php
   else {
        // ???????????????
        }
   }
else {
      ?>
      <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
      Field 1: <input type="text" name="field1" value="">
      Field 2: <input type="text" name="field2" value="">
      Field 3: <input type="text" name="field3" value="">
      <input type="submit" name="submit" value="Submit">
      </form>
      <?php 
      }
?>

Maybe it can be done with curl?
Googling for it gave this example: Execute a HTTP POST Using PHP CURL

I forgot to mention that I not only need to send the data to script2.php, but execute scrit2.php as well. So in other words script1.php should be halted, and the browser should “jump” to script2.php.

I don’t think it can be done without curl.
Any reason why you couldn’t use session variables, or store the data in a database?