• Blogs (9)
    • 📱 236 - 992 - 3846

      📧 jxjwilliam@gmail.com

    • Version: ‍🚀 1.1.0
  • Pass $_POST data between different PHPs

    Blogs20122012-01-16


    Pass $_POST data between different PHPs

    There are at least 3 ways to pass ‘post’ data between scripts except from general processing:

    1. write post data to a $_SESSION variable.

      $_SESSION['post'] = $_POST;
      
      header("Location: script.php");
      
      // in script.php, get back the $_POST data by:
      
      $post = $_SESSION['post'];
    2. write post data to a middle file:

      $fh = fopen($file, 'w') or die("can't open file");
      fwrite($fh, print_r($_POST, true));
      fclose($fh);
      
      // later, use the following way to get back the $_POST data.
      $post = file_get_contents($file);
      print_r($post);
    3. write post data to a middle DB table.

    All the above methods should work, which is better? It is hard to say and depends on real environment.