$filename = ' users.txt ';
$name = Trim ($_post["name"]);
$passwd = Trim ($_post["pass"]);
$str = $username. ' | '. $passwd;
$suc =file_write ($str, $filename);
function File_write ($flag, $tmpfname)
{
if ($handle = fopen ($tmpfname, "a"))
{
Fwrite ($handle, $flag. " \ r \ n ");
Fclose ($handle);
return 1;
}
else return 0;
}
Record name and password on TXT, format is mmm|123456
yyy|123456
My code above, why the first write always empty a line, whether it is blank text or already have data. And sometimes writing blank text, can not succeed, ask the great God help me to optimize under
Reply to discussion (solution)
Tested and did not find what you were saying about the phenomenon
Even though your variable name is wrong.
Tested and did not find what you were saying about the phenomenon
Even though your variable name is wrong.
Dizzy, I tried to seem to be right, it must be I verify that the name is already present in this part of the wrong ...
Can the owner help me to see?
$Logi = File ("Users.txt");
$size = sizeof ($Logi);
foreach ($Logi as $Key = $Val)
{$Data [$Key] = explode ("|", $Val);
}
for ($K = 0; $K < $size; $K + +)
{
$user = $Data [$K] [0];
if ($user ==$_post["name"])
{
echo "This name already exits. Please get another one. ";
Break
}
if ($K = = $size-1)
{$suc =file_write ($str, $filename);}
}
How easy it is to use file_put_contents () directly!