I created a form using html which contains a text box and a password box.
I want when I click on the submit button to save the user and the date he entred to the page in a text file, then in the action page the txt file will be displayed and if there is a carriage return it will do the same in the action page.
this is the code I tried in the action page:
<?php
$mdpx = "BTS12";
$loginx = "BTS";
$login = $_POST['nom'];
$mdp = $_POST['psw'];
if(!empty($login) AND !empty($mdp))
{
if($mdp == $mdpx AND $login == $loginx)
{
$fichier = "monfichier.txt";
$fp = fopen($fichier, "a+");
flock($fp,LOCK_EX);
$text .= 'Nom: '.$login."\r\n".'La date: '.date("d M Y : H i s",strtotime("now"))."\r\n".'****************************'."\r\n";
fputs($fp, $text);
flock($fp,LOCK_UN);
fclose($fp);
$fp = fopen($fichier,"r");
flock($fp,LOCK_SH);
while(!feof($fp))
{
$char = fgetc($fp);
echo ($char == '\r\n') ? '<br/>' : $char;
}
flock($fp,LOCK_UN);
fclose($fp);
}
else
print 'Le nom d\'utilisateur ou bien le mot de passe est incorrect <br/> Cliquer <a href="index.php">ici</a> pour revounir a la page d\'acceuil';
}
else
print 'Veuillez remplir tous les champs <br/> Cliquer <a href="index.php">ici</a> pour revounir a la page d\'acceuil';
?>
but the problem is that the action page doesn’t do the carriage return.
I tried also the method readfile() but it didn’t worked !
Output the file in a
<pre>element: