我一直想使用实际机器的用户名和密码验证网站凭据。我已经研究了其他一些解决方案,但我想这个方法会给我带来最少的问题,因为它已经是一个我知道有效的shell函数,需要很少的设置,而且看起来很容易管理。
抬头,这是我第一次发帖(lol PHP笑话),所以我的格式可能不是那么漂亮。
这是简短的示例脚本。
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$user="username";
$password="password";
$tunnels=array(
0 => array('pipe','r'), // Process std input
1 => array('pipe','w'), // Process std output
2 => array('pipe','w') // Process std error
);
$io=array();
$resource=proc_open("login",$tunnels,$io);
if(!is_resource($resource)) {
// Throw exception or something...
echo "uuh oh";
}
fwrite($io[0],"$user");
fwrite($io[0],"$password");
//fwrite($io[0],"whoami\n");
fflush($io[0]);
fclose($io[0]);
while(!feof($io[1]))
{
echo fgets($io[1]);
}
fclose($io[1]);
fclose($io[2]);
// Close process resource
$result=proc_close($resource);
echo $result;
if($result != 0) {
// There where errors.
}
?>
当我运行它时,输出如下
login: 0
我尝试过更改
fwrite($io[0],"$user");
fwrite($io[0],"$password");
到
fwrite($io[0],"$user\n");
fwrite($io[0],"$password\n");
但现在说
login: Login incorrect login: Login incorrect login: 0
此外,这是在OSX服务器上运行并使用PHP版本5.4.17!如果它适用于其他操作系统,我不知道。