Home  >  Article  >  Backend Development  >  PHP 登陆验证时代码有有关问题

PHP 登陆验证时代码有有关问题

WBOY
WBOYOriginal
2016-06-13 12:50:31832browse

PHP 登陆验证时代码有问题
用户名和账号储存在txt文本上,就是密码验证不了,我试过用户名单独验证能成功,不知道哪里错了。。
$Logi = file ( "users.txt" ); 

$size = sizeof ( $Logi ); 

foreach( $Logi as $Key => $Val ) 
{ $Data [ $Key ] = explode ( "|" , $Val ); } 

for( $K = 0 ; $K  { 
  $user = $Data [ $K ][ 0 ];
  $pass = $Data [ $K ][ 1 ];
  if($user==$_POST[ "user" ]&&$pass==$_POST[ "pass" ])
{
   echo "success";
  }
 else echo "No";
 }

php
------解决方案--------------------
加个rtrim()函数
$Data [ $Key ] = rtrim($Data [ $Key ] );
因为file()函数读取的每一行都包括换行符
Statement:
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