William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

Pass $_POST data between different PHPs

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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: