SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru DeNasio's Avatar
    Join Date
    May 2001
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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 Code:
    <?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 
          
    }
    ?>
    Ballot-Box.net - free polls for webmasters
    FormLog.com - free form processor

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Maybe it can be done with curl?
    Googling for it gave this example: Execute a HTTP POST Using PHP CURL

  3. #3
    SitePoint Guru DeNasio's Avatar
    Join Date
    May 2001
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    Ballot-Box.net - free polls for webmasters
    FormLog.com - free form processor

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    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?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •