Cpanel web hosting - PAGES THAT REMEMBER: SIMPLE LOGIN AND MULTIPAGE FORMS
PAGES THAT REMEMBER: SIMPLE LOGIN AND MULTIPAGE FORMS remove any backslashes from the $_POST array and check that the input meets your minimum requirements. You can t check whether the username is unique until you open the file that contains the registered usernames and passwords, but you know there s no point in going any further if the input is too short or the passwords don t match. So let s build the basic code skeleton. Insert the following code above the DOCTYPE declaration: All this does at the moment is remove backslashes from the $_POST array with the nukeMagicQuotes() function from Chapter 3. Let s check the user input. 3. When checking the length of user input, begin by stripping any whitespace from both ends with trim() and saving the result to a shorter variable. Saving to a shorter variable avoids the need to type out the full $_POST variable name every time. It also makes it easier to incorporate user input in a string because you don t need to worry about the quotes in the $_POST variable name. Then pass the new variable to strlen(), which returns the length of a string. If either the username or password is too short, you need an error message to display. Add this code immediately after the appropriate comment: // check length of username and password $username = trim($_POST[’username’]); $pwd = trim($_POST[’pwd’]); if (strlen($username) < 6 || strlen($pwd) < 6) { $result = 'Username and password must contain at least 6 characters'; } You could check that strlen() is greater than 5. However, you still need to make sure that both passwords match. Consequently, it s more efficient to turn the logic around and test for things that you don t want. In pseudo-code, the logic works like this: if (username or password has less than the minimum) { input is not OK } elseif (the passwords do not match) { input is not OK } else { input is OK to process } 249
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.