PHP is waiting for input from the command line

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

  • Script requests an authorization code from the server (this code will be sent by email)
  • Script expects user to enter authorization code
  • Script continues

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

+47
command-line php
Mar 10 '13 at 12:46
source share
1 answer

The php man page for cli has a comment here that details the solution (copied here for someone else)

<?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"; ?> 
+106
Mar 10 '13 at 12:54 on
source share



All Articles