PHP

Moderators: None (Apply to moderate this forum)
Number of threads: 1847
Number of posts: 5013

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Need Help ASAP!!! Posted by david2012 on 31 Mar 2012 at 10:04 AM
Hi Folks!!

I am trying to create a login script. I do not want to use any DB for Username/Password validation as this is for assignment purposes!!

I have written this so far!! I have no luck in getting this right so far. Please can somebody help me in getting this right!!!

I have usernames and passwords stored in a text file called USERS.TXT in the following format which I need to use for validation during comaprison:

Dave:Dave123
Katie:Katie123
...and so on

PS: I am a brand new beginner in PHP World! :)



<?

// Check if the form has been submitted:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$handle = fopen("users.txt", "r");
// Handle the form:
if ( (!empty($_POST['username'])) && (!empty($_POST['password'])) ) {

if ( (strtolower($_POST['username']) == 'user') && ($_POST['password'] == 'pass') ) { // Correct!

// Do session stuff:
session_start();
$_SESSION['username'] = $_POST['username'];
$_SESSION['loggedin'] = time();

// Redirect the user to the welcome page!
ob_end_clean(); // Destroy the buffer!
header ('Location: welcome.php');
exit();

} else { // Incorrect login details!

print '<p>The login details do not match with those on our system!<br />Please try again.</p>';

}

} else { // Forgot a field.

print '<p>Please make sure you enter both the username and password!<br />Please try again.</p>';

}

} else { // Display the form.
print '<form action="login.php" method="post">
<p>Username: <input type="text" name="username" size="20" /></p>
<p>Password: <input type="password" name="password" size="20" /></p>
<p><input type="submit" name="submit" value="Log In!" /></p>
</form>';

}

?>



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.