note 33947 added to function.virtual

From: Date: Fri, 11 Jul 2003 17:56:32 +0000
Subject: note 33947 added to function.virtual
Groups: php.notes 
Request: Send a blank email to php-notes+get-51927@lists.php.net to get a copy of this message
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")); } ---- Manual Page -- http://www.php.net/manual/en/function.virtual.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33947 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33947&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33947&report=yes

« previous php.notes (#51927) next »