Code: Select all
use Term::ReadKey qw (ReadMode);
ReadMode('noecho');
$password = <STDIN>;
ReadMode('restore');Moderator: General Moderators
Code: Select all
use Term::ReadKey qw (ReadMode);
ReadMode('noecho');
$password = <STDIN>;
ReadMode('restore');Code: Select all
ncurses_noecho();
$password = trim(fgets(STDIN));
ncurses_echo();TheFatherMind At Dangerous-Minds.NET
02-Mar-2004 11:22
Above I took what "christian at gaeking dot de" did and I upgraded it a bit. Rewrote it to my needs in the process. I found one minor bug with what he was doing and I also improved on it....
The bug with what he had is that when you hit the keyboard "Return" key it takes that with the varible. So if you type in 123 it takes "123\n". I needed to detect blank input so I purge off the "\n" on the end to fix it.
The Enhancement. I added some options to the "read". One is that if you optionally specify True for the second option on the ReadText function, it will NOT show what you type. This is good for grabbing passwords. Also I added -er to the options of "read". "-e" allows for standard input coming from the terminal (I use this for shell scripts). Also "-r" turns off the backslash incase you want that as part of your input. This means you can not escape any thing while doing input. Feel free to change the options though. And finally I added the ability to prompt with the input.
Code: Select all
<?php Function ReadText($Prompt,$Silent=False){ $Options="-er"; If($Silent==True){ $Options=$Options." -s"; } $Returned=POpen("read $Options -p \"$Prompt\"; echo \$REPLY","r"); $TextEntered=FGets($Returned,100); PClose($Returned); $TextEntered=SubStr($TextEntered,0,StrLen($TextEntered)-1-1); If($Silent==True){ Print "\n"; @OB_Flush(); Flush(); } Return $TextEntered; } ?>