Guest User

Untitled

a guest
Aug 15th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. Why do I keep getting the Cannot modify header information error PHP? [closed]
  2. <?php
  3.  
  4. $check = 0;
  5. if (isset($_POST['submit']))
  6. {
  7.  
  8. $username = htmlentities($_POST['name']);
  9. $username = strtolower($username);
  10. $password = htmlentities($_POST['apw']);
  11. $filename = getcwd() . "/passwd.txt";
  12. $lines = file( $filename , FILE_IGNORE_NEW_LINES );
  13. foreach($lines as $key => $line)
  14. {
  15. list($name, $pw) = explode(':', $line);
  16. if($name == $username && $pw == $password)
  17. {
  18. $check++;
  19. break;
  20. }
  21. }
  22. if ($check == 1){
  23. checkifPlayed($username);
  24. }
  25.  
  26. else{
  27. printf("Your username or password are invalid. Please try again.");
  28.  
  29. }
  30.  
  31. }
  32. $played = 0;
  33. function checkifPlayed($username) {
  34. $results = getcwd() . "/results.txt";
  35. $lines = file( $results , FILE_IGNORE_NEW_LINES );
  36. foreach($lines as $key => $line)
  37. {
  38. list($name, $score) = explode(':', $line);
  39. if($name == $username)
  40. {
  41. $played++
  42. break; }
  43. if ($played != 1){
  44. //Redirect to page
  45. header("location: news.php");}
  46. else {
  47. printf "You've already played and scored $score / 60.";
  48. }
  49. }
  50. }
  51. ?>
  52.  
  53. <form method = "POST" action = "<?php echo $_SERVER['PHP_SELF']; ?>">
  54. <p>
  55. Username:<br />
  56. <input type = "text" id="name" name="name" size="20" maxlength="40" />
  57. </p>
  58.  
  59. <p>
  60. Password:<br />
  61. <input type = "password" id="apw" name="apw" size="20" maxlength="40" />
  62. </p>
  63.  
  64. <input type="submit" id="submit" name ="submit" name ="submit" value="Log in" />
  65.  
  66. <p>
  67. <a href="register.php">Register</a></p>
  68. </form>
Add Comment
Please, Sign In to add comment