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!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.