Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.98 KB | None | 0 0
  1. <?php
  2. //This checks for required fields from the form.
  3. if ((!$_POST[username]) || (!$_POST[password]))
  4. {
  5. header("Location: P4 LoginForm.php");
  6. exit;
  7. }
  8.  
  9. //This reads values from the form.
  10. $form_user = $_POST[username];
  11. $form_password = $_POST[password];
  12.  
  13. $flag = FALSE;
  14. $filename = "users.txt";
  15. $fp = fopen( $filename, "r" ) or die ("Couldn't open $filename");
  16.  
  17. while ( ! feof( $fp ) ) {
  18. $line = fgets( $fp);
  19. $user = strtok($line, ","); //Username
  20. $password = strtok(","); //Password
  21. if (($form_user == $user) && ($form_password == $password))
  22. {
  23. $flag = TRUE;
  24. }
  25. break;
  26. }
  27.  
  28. if ($flag)
  29. {
  30. echo "<br>Congratulations, you're logged in";
  31. }
  32.  
  33. else{
  34. $filename = "users.txt";
  35. $updateuser = $_POST ['username'];
  36. $updatepass = $_POST ['password'];
  37.  
  38. $fp = fopen( $filename, "a" ) or die("Couldn't open $filename");
  39. fwrite( $fp, "$updateuser,$updatepass\n") or die ("Couldn't write values to your file!");
  40. fclose( $fp );
  41. echo "<br>An account has been created for you!";
  42. }
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement