PHP 等待命令行输入

我希望能够让一个 PHP 程序等待用户的输入。例如:

  1. 脚本从服务器请求授权代码(此代码将通过电子邮件发送)
  2. 脚本等待用户输入授权代码
  3. 剧本继续

我应该怎样做第二步? (可能吗?)

89590 次浏览

The php man page for the cli has a comment here detailing a solution, (copied here for anyone else looking)

<?php
echo "Are you sure you want to do this?  Type 'yes' to continue: ";
$handle = fopen ("php://stdin","r");
$line = fgets($handle);
if(trim($line) != 'yes'){
echo "ABORTING!\n";
exit;
}
fclose($handle);
echo "\n";
echo "Thank you, continuing...\n";
?>