Web host forum - PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY 3.

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY 3. Add the following short code block just after the opening tag to display any error messages, and save login.php: $error

“; } ?>

Sharp-eyed readers will probably have noticed that the code in the loop in step 2 could be simplified like this: for ($i = 0; $i < count($users); $i++) { // separate each element and store in a temporary array $tmp = explode(', ', $users[$i]); // check for a matching record if ($tmp[0] == $_POST['username'] && rtrim($tmp[1]) == . $_POST['pwd']) { // if there's a match, set a session variable $_SESSION['authenticated'] = 'Jethro Tull'; break; } } There is no need to assign the name and password to named array elements, because you don t need the values after you ve found a match. The reason I left in the line that assigns each element of the temporary array to a named key is because it makes the script easier to understand. When developing scripts, I often find it s better to use explicit steps like this, rather than attempt to use the shortest possible code. Short code can be very satisfying, but it s often more difficult to read and troubleshoot. Now, before you can test login.php, you need to create menu.php and restrict access with a session. PHP Solution 9-4: Restricting access to a page with a session The code for this section is in menu01.php and secretpage01.php in the download files for this chapter. 1. Create two pages in the sessions folder called menu.php and secretpage.php. It doesn t matter what they contain, as long as they link to each other. 2. Protect access to each page by inserting the following above the DOCTYPE declaration: We recommend high quality webhost to host and run your jsp application: christian web host services.

Leave a Reply