我在个人 Ubuntu Server 机器上有这个 PHP 代码:
$cmd = 'su testuser'; $descriptorspec = 数组( 数组('管道','r'), 数组('管道','w'), 数组('管道','w') ); $pipes = 数组(); $process = proc_open($cmd, $descriptorspec, $pipes); fwrite($pipes[0], '密码\r'); fclose($pipes[0]); $string = array(stream_get_contents($pipes[1]), stream_get_contents($pipes[2])); proc_close($进程); 回声 exec('whoami') 。"\n"; print_r($string);
我从 PHP 得到这个响应:
www-数据 大批 ( [0] => [1] => su: 必须从终端运行 )
很明显我想更改活动用户但是有什么办法可以从 php 中做到这一点?