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!


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:

...and so on

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


// Check if the form has been submitted:
$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['username'] = $_POST['username'];
$_SESSION['loggedin'] = time();

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

} 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 '





Sign In or Register to comment.