PAGES THAT REMEMBER: SIMPLE LOGIN (Free web hosting services) AND MULTIPAGE FORMS

PAGES THAT REMEMBER: SIMPLE LOGIN AND MULTIPAGE FORMS if (isset($_SESSION[’name’])) { // if set, greet by name echo ‘Hi, ‘.$_SESSION[’name’].’. Next‘; } else { // if not set, send back to login echo ‘Who are you? Login‘; } ?> If $_SESSION[’name’] has been set, a welcome message is displayed along with a link to session03.php. Otherwise, the page tells the visitor that it doesn t recognize who s trying to gain access, and provides a link back to the first page. Take care when typing the following line: echo ‘Hi, ‘.$_SESSION[’name’].’. Next‘; The first two periods (surrounding $_SESSION[’name’]) are the PHP concatena- tion operator. The third period (immediately after a single quote) is an ordinary period that will be displayed as part of the string. 4. Create session03.php. Type the following above the DOCTYPE to initiate the session: 5. Insert the following code between the tags of session03.php: ‘; // unset session variable unset($_SESSION[’name’]); // invalidate the session cookie if (isset($_COOKIE[session_name()])) { setcookie(session_name(), ‘’, time()-86400, ‘/’); } // end session session_destroy(); echo ‘Page 2‘; } else { // display if not recognized echo ‘Sorry, I don’t know you.
‘; echo ‘Login‘; } ?> 239
Check Tomcat Web Hosting services for best quality webspace to host your web application.

Leave a Reply