echoed密码输入字段显示为文本

时间:2013-05-29 12:44:51

标签: php html apache passwords

我试图使用带有XAMPP(Apache和MYSQL)的php创建一个简单的注册表单。我目前的密码字段有问题,该字段当前将其输入显示为明文,而不是将其隐藏在视图中。 / p>

?php
$regfields=array("remail"=>"Email","remail2"=>"Re-enter     Email","rusername"=>"Username","rpassword"=>"Password","rpassword2"=>"Re-enter Password","rbiz"=>"BizName","rdesc"=>"Desc");
?>

<html>
<body>
<h3>Registration</h3>
<form action="Login.php" name="RegisterForm" method="post" >
<table border="0">

<?php

if(isset($errormsg))
{
    echo"$errormsg";
}

foreach($regfields as $field=>$value)
{

    if($field!=="rdesc")
    {
        echo"<tr>";
        echo"<td>";
        echo"<label for='$field'>$value: </label>";
        echo"</td>";
        echo"<td>";
        echo"<input type='text' name='$field' size='40' maxlength='50' />    </td></tr>";

    }
    else if($field=="remail"||$field=="remail2")
    {
        echo"<tr>";
        echo"<td>";
        echo"<label for='$field'>$value: </label>";
        echo"</td>";
        echo"<td>";
        echo"<input type='text' name='$field' size='40' maxlength='50' /></td></tr>";

    }
    else if($field=="rpassword"||$field=="rpassword2")
    {
        echo"<tr>";
        echo"<td>";
        echo"<label for='$field'>$value: </label>";
        echo"</td>";
        echo"<td>";
        echo"<input type='password' name='$field' size='40' maxlength='50' /></td></tr>";

    }
    else
    {
        echo"<tr>";
        echo"<td>";
        echo"<label for=$field>$value: </label>";
        echo"</td>";
        echo"<td>";
        echo"<input type='text' name='$field' size='300' maxlength='300' style='width:400px;height:100px; \n'/>";
        echo"</td>";
        echo"</tr>";
    }
}

?>
</form>
</table>
<input type="submit" name="Button" value="Register" />
</body>
</html>

我怀疑我的问题源于这一行

echo"<input type='password' name='$field' size='40' maxlength='50' /></td></tr>";

由于使用单引号而输入类型未注册,而不是双引号导致输入类型按字面解释而不用作值?

我将不胜感激。 谢谢!

2 个答案:

答案 0 :(得分:2)

哦,看看这个

以下代码始终执行,除非字段为rdesc。因此,请从!

中删除if($field!=="rdesc")来更正您的代码
  if($field!=="rdesc")
    {
        echo"<tr>";
        echo"<td>";
        echo"<label for='$field'>$value: </label>";
        echo"</td>";
        echo"<td>";
        echo"<input type='text' name='$field' size='40' maxlength='50' />    </td></tr>";

    }

答案 1 :(得分:1)

如果您发现单引号和双引号的使用令人困惑,请尝试使用

<?php
else if($field=="rpassword"||$field=="rpassword2")
    {?>

<tr>
    <td>
        <label for="<?php echo $field?>"><?php echo $value?>: </label>
        </td>
        <td>
        <input type="password" name="<?php echo $field?>" size='40' maxlength='50' /></td></tr>
<?php
    }?>

HTML

中回复PHP并不是一个好的做法