PHP wait for input from command line [duplicate]

I want to be able to let a PHP program wait for user's input. For example:

  1. Script requests authorization code from server (this code will be sent via e-mail)
  2. Script waits for user to enter authorization code
  3. Script continues

How should I do step 2? (Is it possible?)


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