Jump to content
Larry Ullman's Book Forums

dalmation8429

Members
  • Content Count

    4
  • Joined

  • Last visited

Everything posted by dalmation8429

  1. OK, echo n12br(file_get_contents($file)) works for both of them now. Both login.php and register.php can display what's currently in the text file. One of the periods got lost in the third line. Must have accidentally deleted one somehow. And now even better news. Login.php finally worked! It says "You are now logged in!" Not exactly sure what made it work (the period wasn't always a problem--see first post), but it works now. Anyhow, thanks for the help HartleySan. Now I can happily continue on in the book
  2. How would I go about getting the values in the text file? I tried using this code in login.php, echo nl2br(file_get_contents($file)) ...but nothing happened. It returned a blank line where the output should have been. Out of curiosity, I tried the code in register.php and it showed everything in the text file perfectly. I just don't get it. What is it about my login.php that's making it not acknowledge my text file at all?
  3. @HartleySan Thanks. I inserted both strlen and echo into login. php. The results showed the same thing as what was put in with register.php. There's nothing extra. This is the code I used: print strlen($_POST['username'])."<br>"; print strlen(md5(trim($_POST['password'])))."<br>"; echo md5(trim($_POST['password']))."<br>"; echo $_POST['username'];
  4. Hi everyone. I've done everything I could think of to get Script 11.8 to work, but I keep getting the error message 'The username and password you entered do not match those on file'. The users.txt is where it should be (because it worked fine for register.php) and the script is almost exactly how it is in the book. I'm using the same user names and passwords as well. Is this happening because I'm on a Mac? Oh, I'm on PHP 5.3.6 and use XAMPP. <?php // Script 11.8 - login.php $file = '../users/users.txt'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Handle the form. $loggedin = FALSE; // Not currently signed in. // Enable auto_detect_line settings: ini_set('auto_detect_line_endings', 1); // Open the file: $fp = fopen($file, 'rb'); // Loop through the file: while ( $line = fgetcsv($fp, 200, "\t") ) { // Check the file data against the submitted data: if ( ($line[0] == $_POST['username']) AND ($line[1] == md5(trim($_POST['password']))) ) { $loggedin = TRUE; // Correct username/password combination. // Stop looping through the file: break; } // End of IF. } // End of WHILE. fclose ($fp); // Close the file. // Print a message: if ($loggedin) { print '<p>You are now logged in.</p>'; } else { print '<p style="color: red;">The username and password you entered do not match those on file.</p>'; } } else { // Display the form. // Leave PHP and display the form: ?> <form action="login.php" method="post"> <p>Username: <input type="text" name="username" size="20" /></p> <p>Password: <input type="password" name="password" size="20" /></p> <input type="submit" name="submit" value="Login" /></form> <?php } // End of submission IF. ?> </body> </html>
×
×
  • Create New...