PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 30th, 2012, 10:31 AM
spanishflea spanishflea is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 1 spanishflea User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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_usersfilesize('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!

Reply With Quote
  #2  
Old November 30th, 2012, 10:51 AM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,877 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 22 h 59 m 34 sec
Reputation Power: 581
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.

Reply With Quote
  #3  
Old December 1st, 2012, 09:58 AM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,931 E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 7 h 48 m 54 sec
Reputation Power: 7053
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.
__________________
PHP FAQ
How to program a basic, secure login system using PHP

Quote:
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

Reply With Quote
  #4  
Old December 1st, 2012, 03:00 PM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,877 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 22 h 59 m 34 sec
Reputation Power: 581
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP-General - Creating a Login and Registation Page

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap