php制作文件数据库的登陆与注册

写入php换行函数

$name=$_POST["zhanghao"];

$code=$_POST["code"];

$myfile=fopen("asd.txt","w");

fputs($myfile,$name."\r\n");

fputs($myfile,$code."\r\n");

fclose($myfile);

?>

php读取文件验证登陆信息

$a=$_POST["yonghu"];

$b=$_POST["code"];

$yanzheng=array();

$q=0;

$myfile=fopen("asd.txt","r");

while(!feof($myfile))

{

$order=array("\r\n","\n","\r");

$replace="";

$yanzheng[$q]=str_replace($order,$replace,fgets($myfile));

$q++;

}

fclose($myfile);

$yanzheng=array_filter($yanzheng);

if($a!=$yanzheng[0]||$b!=$yanzheng[1])

{

echo "用户名错误";

}

else

{

echo "成功登陆";

}

?>

ps:

$order=array("\r\n","\n","\r");

$replace="";

$yanzheng[$q]=str_replace($order,$replace,fgets($myfile));

将从文件中读取到到的"\r\n"转义为空白

函数介绍

你可能感兴趣的:(php制作文件数据库的登陆与注册)