gpt4 book ai didi

PHP等待来自命令行的输入

转载 作者:IT老高 更新时间:2023-10-28 12:01:17 26 4
gpt4 key购买 nike

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

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

我应该如何执行第 2 步? (有可能吗?)

最佳答案

cli 的 php 手册页有 comment here详细说明解决方案,(此处复制以供其他人查看)

<?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等待来自命令行的输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15322371/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com