Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Hide password input in CLI PHP script?
July 12, 2007, 10:56 pm
rate this thread
I have a command line PHP script that logs into a network service with
a user name specified on the command line. The script then prompts for
Currently the password is echoed on the screen/terminal as it is
Is it possible to stop the password being echoed on the command line
while it is typed? Or perhaps just print asterix's instead of the
A few details: platform is Linux, PHP version is 4.3.9.
Re: Hide password input in CLI PHP script?
Indeed. As an example, the following command ought to prompt for a
password and save it into a file called "foo" without echoing it to the
stty -echo; echo -n 'Password:'; head -n1 >foo; echo ''
with a bit of imagination, it should be pretty easy to see how you can
work this into a PHP program:
echo 'Password: ';
$pwd = preg_replace('/\r?\n$/', '', `stty -echo; head -n1`);
echo "Your password was: .\n";
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 22 days, 15:34.]
demiblog 0.2.0 Released