PAGES THAT REMEMBER: SIMPLE LOGIN AND MULTIPAGE FORMS (Web site developers)
PAGES THAT REMEMBER: SIMPLE LOGIN AND MULTIPAGE FORMS The inline comments explain what is going on; and you should recognize most of the elseif clause from PHP Solution 9-5. PHP measures time in seconds, and I ve set $timelimit (in line 5) to a ridiculously short 15 seconds purely for demonstra tion purposes. To set a more reasonable limit of, say, 15 minutes, change this later like this: $timelimit = 15 * 60; // 15 minutes You could, of course, set $timelimit to 900, but why bother when PHP can do the hard work for you? If the sum of $_SESSION[’start’] plus $timelimit is less than the current time (stored as $now), you end the session and redirect the user to the login page. The line that performs the redirect adds a query string to the end of the URL like this: http://localhost/phpsolutions/sessions/login.php?expired=yes The code in step 2 takes no notice of the value of expired; adding yes as the value just makes it look user-friendlier in the browser address bar. If the script gets as far as the final else, it means that $_SESSION[’authenticated’] has been set, and that the time limit hasn t been reached, so $_SESSION[’start’] is updated to the current time, and the page displays as normal. 4. Copy the code in the preceding step, and use it to replace the code above the DOCTYPE declaration in secretpage.php. 5. Save all three pages, and load either menu.php or secretpage.php into a browser. If the page displays, click Log out. Then log back in, and navigate back and forth between menu.php and secretpage.php. Once you have verified that the links work, wait 15 seconds or more, and try to navigate back to the other page. You should be automatically logged out and presented with the following screen: The code in step 2 is quite long, and is identical for every page that requires it, so it s an ideal candidate for turning into an include. That way, you need update only one script if you decide to change the time limit or the redirect page. The start_session() command can also go in the include file as long as it comes before the use of any session variables. 255
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.