Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'chapter 11 pursue'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 1 result

  1. Hi all: I am just starting to work on the pursue for chapter 11 on the register.php file.The instructions say to create a system to guarantee unique usernames in register.php. Before you attempt to create the directory, use PHP to check your list of existing usernames for a match to the just-registered name. If no match is found, thenew name is acceptable. If the username is already in use, the PHP can create an error message requesting a new username. I am needing a new way of thinking - I guess. The lines of code that I added that was not given to me, I placed in bold. I am hoping this will search the directory for the usernames listed...But this is where I get stumped... In the line of code I have written, I am asking it to search the text file for the names that were submitted - thus the scandir() function. How do I write this if statement so that it all makes sense with the rest of the code? and when the directions "before" you create your directory, do they mean that I should have placed my new code up above this line of text: $dir = '../users/'; $file = $dir . 'users.txt'; Or am I supposed to create a new directory. That really won't make sense to me, because the data is already being stored in a text file as indicated in this line: $file = $dir . 'users.txt'; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Register</title> <style type="text/css" media="screen"> .error { color: red; } </style> </head> <body> <h1>Register</h1> <?php // Script 11.6 - register.php /* This script registers a user by storing their information in a text file and creating a directory for them. */ // Identify the directory and file to use: $dir = '../users/'; $file = $dir . 'users.txt'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Handle the form. $problem = FALSE; // No problems so far. // Check for each value... if (empty($_POST['username'])) { $problem = TRUE; print '<p class="error">Please enter a username!</p>'; } if (empty($_POST['password1'])) { $problem = TRUE; print '<p class="error">Please enter a password!</p>'; } if ($_POST['password1'] != $_POST['password2']) { $problem = TRUE; print '<p class="error">Your password did not match your confirmed password!</p>'; } if (!$problem) { // If there weren't any problems... if (is_writable($file)) { // Open the file. // Create the data to be written: $subdir = time() . rand(0, 4596); $data = $_POST['username'] . "\t" . md5(trim($_POST['password1'])) . "\t" . $subdir . PHP_EOL; // Write the data: file_put_contents($file, $data, FILE_APPEND | LOCK_EX); // Create the directory: mkdir ($dir . $subdir); // Print a message: print '<p>You are now registered!</p>'; } else { // Couldn't write to the file. print '<p class="error">You could not be registered due to a system error.</p>'; } } else { // Forgot a field. print '<p class="error">Please go back and try again!</p>'; } } else { // Display the form. $search_dir + '.'; $file = scandir($search_dir); foreach($contents as $item) { if } // Leave PHP and display the form: ?> <form action="register.php" method="post"> <p>Username: <input type="text" name="username" size="20" /></p> <p>Password: <input type="password" name="password1" size="20" /></p> <p>Confirm Password: <input type="password" name="password2" size="20" /></p> <input type="submit" name="submit" value="Register" /> </form> <?php } // End of submission IF. ?> </body> </html>
×
×
  • Create New...