php验证两次输入的密码一致怎样处理"0"解决思路

WBOY
Release: 2016-06-13 13:45:06
Original
1903 people have browsed it

php验证两次输入的密码一致怎样处理"0"?
请教一下:非常简单的验证两次输入的密码是否一致,遇到奇怪的问题:如果第一次输入了“00000”,第二次输入了“000”,程序就认为是一致的,也就是当用户输入的密码都为0时,不管几个0,都能通过。

代码:

// 定义管理员变量,如提交则为提交的值,否则默认为admin
$admname = (isset($_POST['admname'])) ? trim($_POST['admname']) : 'admin';

if (isset($_POST['submitted']))
{
  $admpass1 = (isset($_POST['admpass1'])) ? trim($_POST['admpass1']) : '';
  $admpass2 = (isset($_POST['admpass2'])) ? trim($_POST['admpass2']) : '';
   
  if ($admname !='' && $admpass1 !='' && ($admpass1 == $admpass2))
  {
  …… ……

------解决方案--------------------
试试 ===
------解决方案--------------------
比较md5的加密结果。
------解决方案--------------------
可能只是比较数值吧,显式转化为字符串类型看看
------解决方案--------------------

探讨

非常感谢楼上几位的回复!用了 === 就解决了。

不过只是简单的字符串比较,不知为什么还要限制数据类型?两个都是字符串呵。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!