PHP等待输入命令行[重复](PHP wait for input from command lin

2019-07-21 06:43发布

这个问题已经在这里有一个答案:

  • 使用PHP交互shell 8个回答

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

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

我应该怎么做第2步? (可能吗?)

Answer 1:

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";
?>


文章来源: PHP wait for input from command line [duplicate]