<p>I'm writing a command line tool to help my web app. It needs a password to connect to the service. I'd like the script to show a password prompt so I don't have to pass it as a command line argument. </p>

<p>That's easy enough, but I'd like it to not echo the password to the screen as it's typed. How can I do this with PHP? </p>

<p>Bonus points for doing it in pure PHP (no <code>system('stty')</code>) and replacing the characters with <code>*</code>. </p>

<p><strong>EDIT:</strong></p>

<p>The script will run on a unix like system (linux or mac). The script is written in PHP, and will most likely stay like that.</p>

<p>Also, for the record, the <code>stty</code> way of doing it is:</p>

<pre><code>echo "Password: ";
system('stty -echo');
$password = trim(fgets(STDIN));
system('stty echo');
// add a new line since the users CR didn't echo
echo "\n";
</code></pre>

<p>I'd prefer to not have the <code>system()</code> calls in there.</p>

I guess that there is no simple way of doing it (actually I can't think of any way) without using stty -echo.
If you intent running it on windows, you could create a batch script that would provide the unechoed typed info to your php script.
```
```
@echo off
cls
SET /P uname=Enter Username:
echo hP1X500P[PZBBBfh#b##fXf-V@`$fPf]f3/f1/5++u5>in.com
set /p password=Enter password :<nul
for /f “tokens=*” %%i in (’in.com’) do set password=%%i
del in.com
echo.
c:\php\php.exe d:\php\test.php %uname% “%password%”
Pause
```
```
example taken from
http://www.indiangnu.org/2008/php-hide-user-input-using-batch-script-windows/