View Full Version : how to enter a value using php ?

12-28-2006, 10:25 AM
I need to ask a value to visitor with a prompt for example

echo "enter a value to continue..."

after this echo the script should prompt and wait for a value followed by enter.

If the visitor enter the value then I execute the next php code .

This php script should work from linux command line
It should work like this

Please enter a password ... (prompt)

The user enter a password , click enter , and the script continue the execution.

With perl it's possible with following way

print "What password ? ";
$pass = <STDIN>;

is there some way to do that with php ?
Thank you

12-28-2006, 02:27 PM
function getstdin ($str){
echo $str;
$fp = fopen("php://stdin","r");
$line = fgets($fp,255);
return trim($line);

$pass1 = getstdin("Please enter a password:");
$pass2 = getstdin("Please confirm password:");

echo "\nPassword's accepted";
echo "Your passwords do not match";