Need Help ASAP!!! - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Need Help ASAP!!!

david2012david2012 Posts: 1Member
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!
Please try again.';

}

} else { // Forgot a field.

print '

Please make sure you enter both the username and password!
Please try again.

';

}

} else { // Display the form.
print '

Username:

Password:

';

}

?>
Sign In or Register to comment.