The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
PHP-General - Creating a Login and Registation Page
Discuss Creating a Login and Registation Page in the PHP Development forum on Dev Shed. Creating a Login and Registation Page PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 30th, 2012, 10:31 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 1
Time spent in forums: 5 m 32 sec
Reputation Power: 0
|
|
|
PHP-General - Creating a Login and Registation Page
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.
newaccount.html:
Code:
<html>
<head>
</head>
<body>
<h3>Hello new user! Choose a user name and password ^_^</h3><br>
<form action = "register.php" method = "POST" >
Username: <input type = "text" name = "username"><br><br>
Password: <input type = "password" name = "pass"><br>
<input type = "submit" value = "Create Account" name = "submit"><br>
</form>
<form method = "LINK" action = "Proj2_practice.html">
<input type = "submit" value = "Home Page" name = "submit2">
</form>
</body>
</html>
register.php:
PHP Code:
<?php
$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 ^_^
Thank you in advance!
|

November 30th, 2012, 10:51 AM
|
|
|
|
For one thing, you never close the output files before trying to read. For another, I am wondering why you are doing it this unsecure way when there are already secure ways built-in?
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.
|

December 1st, 2012, 09:58 AM
|
 |
Lost in code
|
|
|
|
Quote: | For another, I am wondering why you are doing it this unsecure way when there are already secure ways built-in? |
"this is an assignment for class" is a get out of jail free card for bad design.
You seem to be adding an extra space to the end of your text file names. This isn't related to your problem though.
Try adding fseek($fh_users, 0) before your call to fread. Don't call it before fwrite though or you will overwrite your file.
Also file_get_contents is a better way to read the whole contents of a file into a variable.
I'm not quite sure what gw1500se means about closing the output files before trying to read. You wouldn't want to call fclose on the handle before fread or it will error out.
|

December 1st, 2012, 03:00 PM
|
|
|
|
For a sequential file I meant close it after write then open it for read. I've had bad luck with fseek in the past so I never use it.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|