note 83436 added to function.popen

From: Date: Mon, 26 May 2008 12:26:52 +0000
Subject: note 83436 added to function.popen
Groups: php.notes 
Request: Send a blank email to php-notes+get-139792@lists.php.net to get a copy of this message
To complete the examples below that use proc_open to encrypt a string using GPG, here is a decrypt function: function gpg_decrypt($string, $secret) { $homedir = ''; // path to you gpg keyrings $tmp_file = '/tmp/gpg_tmp.asc' ; // tmp file to write to file_put_contents($tmp_file, $string); $text = ''; $error = ''; $descriptorspec = array( 0 => array("pipe", "r"), // stdin 1 => array("pipe", "w"), // stdout 2 => array("pipe", "w") // stderr ?? instead of a file ); $command = 'gpg --homedir ' . $homedir . ' --batch --no-verbose --passphrase-fd 0 -d ' . $tmp_file . ' '; $process = proc_open($command, $descriptorspec, $pipes); if (is_resource($process)) { fwrite($pipes[0], $secret); fclose($pipes[0]); while($s= fgets($pipes[1], 1024)) { // read from the pipe $text .= $s; } fclose($pipes[1]); // optional: while($s= fgets($pipes[2], 1024)) { $error .= $s . "\n"; } fclose($pipes[2]); } file_put_contents($tmp_file, ''); if (preg_match('/decryption failed/i', $error)) { return false; } else { return $text; } } ---- Server IP: 69.147.83.197 Probable Submitter: 79.112.1.94 ---- Manual Page -- http://www.php.net/manual/en/function.popen.php Edit -- https://master.php.net/note/edit/83436 Del: integrated -- https://master.php.net/note/delete/83436/integrated Del: useless -- https://master.php.net/note/delete/83436/useless Del: bad code -- https://master.php.net/note/delete/83436/bad+code Del: spam -- https://master.php.net/note/delete/83436/spam Del: non-english -- https://master.php.net/note/delete/83436/non-english Del: in docs -- https://master.php.net/note/delete/83436/in+docs Del: other reasons-- https://master.php.net/note/delete/83436 Reject -- https://master.php.net/note/reject/83436 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139792) next »