Creating a Registration and Login Page

Hey everyone, I’m currently in the process of making a Registration and Login Page. My first page asks you if you want to create an account or login. What we have to do is take the information from the form that the user enters information into, and place it into a text file. I’ve got this working roughly. I understand that this is not good practice for security reasons, but this is an assignment for class and I MUST put the information into the text file. I have the information going into the text file, however I am having trouble comparing the posted username to all of the usernames inside of the database. Here is my code for the newaccount.html page, and the register.php file that the form submits to.



Hello new user! Choose a user name and password ^_^






$username = $_POST[‘username’];

$password = $_POST[‘pass’];

$userAndPass = $username.",".$password;

$userNames = ‘usernames.txt’." ";

$passwords = ‘passwords.txt’." ";

$fh_users = fopen($userNames, ‘a+’)or die(“sorry, we couldnt open the file”);

$fh_passwords = fopen($passwords, ‘a+’)or die(“sorry, we couldnt open the file”);

fwrite($fh_users, $username." ");

fwrite($fh_passwords, $password." ");

$allUserNames = fread($fh_users, filesize(‘usernames.txt’));

echo $allUserNames;


The usernames and passwords are being sent to the text files correctly, At the end of the code, it is not echoing the variable. As of right now, there is no information in the text files, I don’t know if that is the reason that nothing is being echoed. Is my approach correct here? What I’m trying to do here is send each name and password to a username and password text file.Then, Im planning on exploding each of those text files by a space between them, which is why I add one after writing them to the text file, and then comparing the usernames and the passwords by their respective array elements. Am I overcomplicating this as much as I think I am? Please share your comments with me, I’m just trying to get better :slight_smile:

Thank you in advance!

How are you doing the comparison?

Sponsor our Newsletter | Privacy Policy | Terms of Service