doushan5222 2015-05-27 06:50
浏览 93
已采纳

如何确保php / html登录表单不会在用户名和密码字段中加载值

I have written this simple php code (see below). The problem is that when i try running this code, the form loads values into both the username and password input fields. I have tried setting autocomplete = "off" in both the form tag and the input tag as suggested here but it does not seem to work. My browser if firefox 38.0 for Ubuntu canonical 1.0. What is the problem here?

<?php

if (isset($_POST['submit']) && !empty($_POST['username']) && !empty($_POST['password'])){echo "yesu";
  $username = $_POST['username']; 
  $password = md5 ($_POST['password'] . 'ijdb');
  print "welcome $username";
/*header ('Location: .');
exit();*/

  }
    else{
?>
<form action = "" method = "post" autocomplete = "off">
Username: <input type = "text" name = "username" autocomplete = "off"/><p>
Password: <input type = "password" name = "password" autocomplete = "off"/><p>
<input type = "submit" name = "submit" value = "login"/>
<form>
<?php
  }
?>

</div>
  • 写回答

4条回答 默认 最新

  • douchuilai2355 2015-05-27 06:58
    关注

    Put a hidden empty text field between username and password

    <input type="text" name="username">
    <input type="text" style="display:none">// like this 
    <input type="password" style="display:none">// Introducing this line ensures that whenever you load the form the password field is blank
    <input type="password" name="password">
    

    Explain

    It will make the username text field not to show any previously typed words in a drop down. Since there is no attribute like name, id for the input field it wouldn't send any extra parameters also.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题