Skip to content

Instantly share code, notes, and snippets.

@scribu
Created June 27, 2013 15:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scribu/5877523 to your computer and use it in GitHub Desktop.
Save scribu/5877523 to your computer and use it in GitHub Desktop.
CLI: Prompt for sensitive data, like passwords, but hide input
<?php
/**
* Ask for input, but make it hidden.
*/
function ask_hidden( $prompt ) {
echo $prompt;
echo "\033[30;40m"; // black text on black background
$input = fgets( STDIN );
echo "\033[0m"; // reset
return rtrim( $input, "\n" );
}
$pass = ask_hidden( 'pass: ' );
var_dump( $pass );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment