note 33947 deleted from function.virtual by sniper

From: Date: Sat, 22 Nov 2003 02:30:02 +0000
Subject: note 33947 deleted from function.virtual by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-60803@lists.php.net to get a copy of this message
Note Submitter: abentley@panoramicfeedback.com ---- Here's a function for executing CGI scripts that 1. works with GET or POST 2. accepts any number of headers 3. allows headers to pass through (if possible) 4. does not execute the output as a PHP script However it 5. does not pass all environment variables 6. is not safe for binary output 7. requires the always_populate_raw_post_data configuration directive to be on. 8. uses the real file path, not a virtual path Note: the raw post data appears to be the only way to retrieve/reconstruct the unadulterated POST form submission in php 4.1.0. The $_POST array mutiliates variable names that contain periods. Such names are produced by image buttons (foo.x=10&foo.y=5), for example. It appears that PHP 4.2.0 and 4.3.0 each add support for better ways of achieving this(4.2.0: popen, 4.3.0: proc_open). I use Debian Woody and Red Hat 7.3, so I'm sticking with 4.1.0 function exec_cgi($CGISCRIPT) { // preparing the arguments passed to this PHP page $QSTRING = $_SERVER['QUERY_STRING']; putenv('REQUEST_METHOD='.$_SERVER['REQUEST_METHOD']); putenv('CONTENT_TYPE=application/x-www-form-urlencoded'); putenv('CONTENT_LENGTH='.$_SERVER['CONTENT_LENGTH']); if ($_SERVER['QUERY_STRING']!='') putenv('QUERY_STRING='.$_SERVER['QUERY_STRING']); unset($return_array); global $HTTP_RAW_POST_DATA; exec('echo -n '.escapeshellarg($HTTP_RAW_POST_DATA).'| '.$CGISCRIPT, $return_array, $return_val); // handle headers $doheaders=!headers_sent(); do { $headerline=array_shift($return_array); if ($do_headers) header($headerline); } while($headerline!=""); //handle body print(implode($return_array,"\n")); }

« previous php.notes (#60803) next »