PAGES THAT REMEMBER: (Abyss web server) SIMPLE LOGIN AND MULTIPAGE FORMS
PAGES THAT REMEMBER: SIMPLE LOGIN AND MULTIPAGE FORMS // if session variable not set, redirect to login page if (!isset($_SESSION[’authenticated’])) { header(’Location: http://localhost/phpsolutions/sessions/login.php’); exit; } ?> After starting the session, the script checks whether $_SESSION[’authenticated’] has been set. If it hasn t, it redirects the user to login.php and exits. That s all there is to it! The script doesn t need to know the value of $_SESSION[’authenticated’], although you could make doubly sure by amending line 4 like this: if (!isset($_SESSION[’authenticated’]) || $_SESSION[’authenticated’] . != ‘Jethro Tull’) { This now also rejects a visitor if $_SESSION[’authenticated’] has the wrong value. 3. Save menu.php and secretpage.php, and try to load either of them into a browser. You should always be redirected to login.php. 4. Enter a valid username and password in login.php, and click Log in. You should be redirected immediately to menu.php, and the link to secretpage.php should also work. All you need to do to protect any page on your site is add the eight lines of code in step 2 above the DOCTYPE declaration. As well as logging into a site, users should be able to log out. PHP Solution 9-5: Creating a reusable logout button Continue working with the files from the preceding section. The finished files are in menu03.php, logout.inc.php, and secretpage02.php in the download files for this chapter. 1. Create a logout button in the
of menu.php by inserting the following form: The page should look similar to the following screenshot: 245
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.