PHP 这代码只获取到txt的最后一行
<?$username=$_POST['user'];$password=$_POST['pwd'];functionload(){$user_array=array()...
<?
$username=$_POST['user'];
$password=$_POST['pwd'];
function load(){
$user_array=array();
$fp = fopen("user.txt","r");
$i=0;
while(! feof($fp)){
$line=fgets($fp,1024);
list($user,$pwd)=explode("|",$line);
$user=trim($user);
$pwd=trim($pwd);
$user_array[i]=array($user,$pwd);
$i++;
}
fclose($fp);
return $user_array;
}
$user_array=load();
if(!in_array(array($username,$password),$user_array)){
echo "用户或者密码错误";
header("location:e5-login.php");
}
else {
foreach($user_array as $value){
list($user,$pwd)=$value;
if($user==$username&&$pwd==$password)
{
session_start();
$_SESSION['user']=$username;
$_SESSION['pwd']=$password;
header("location:e5.php");
}
}
}
?> 展开
$username=$_POST['user'];
$password=$_POST['pwd'];
function load(){
$user_array=array();
$fp = fopen("user.txt","r");
$i=0;
while(! feof($fp)){
$line=fgets($fp,1024);
list($user,$pwd)=explode("|",$line);
$user=trim($user);
$pwd=trim($pwd);
$user_array[i]=array($user,$pwd);
$i++;
}
fclose($fp);
return $user_array;
}
$user_array=load();
if(!in_array(array($username,$password),$user_array)){
echo "用户或者密码错误";
header("location:e5-login.php");
}
else {
foreach($user_array as $value){
list($user,$pwd)=$value;
if($user==$username&&$pwd==$password)
{
session_start();
$_SESSION['user']=$username;
$_SESSION['pwd']=$password;
header("location:e5.php");
}
}
}
?> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询