Script 12.1
Your Website
catchy slogan...
Login
<?php # Script 12.1 - login_page // This page prints any errors associated with logging in // and it creates the entire login page, including the form. $page_title = 'Login'; // Include the proper header and error values: $ref = (isset($_SERVER['QUERY_STRING']))? $_SERVER['QUERY_STRING']: 'cookies'; if(strpos( $ref, 'using+cookies' )){ include (CHAPTER_PATH.'/'.$chapter.'/includes/12.7.php'); if(isset($_COOKIE['errors'])) { $errors = (unserialize($_COOKIE['errors'])); } } else { include (CHAPTER_PATH.'/'.$chapter.'/includes/12.10.php'); if(isset($_SESSION['errors'])) { $errors = $_SESSION['errors']; } if(isset($_SESSION['email'])) { $email = $_SESSION['email']; } } //begin content output echo "<div id='content'>"; //for testing purposes - output current user status // $cookies_status = (isset($_COOKIE['user_id']))?"Logged in.":"Not logged in."; // $session_exists = (isset($_COOKIE[SESSION_NAME]))?"Session started.": "No session started."; // $session_status = (isset($_SESSION['user_id']))?"Logged in.":"Not logged in."; // echo "<div><h2>User Status</h2><ul>"; // echo "<li><b>Cookie Status</b>: ".$cookies_status.'</li>'; // echo "<li><b>Session Exists</b>: ".$session_exists.'</li>'; // echo "<li><b>Session Status</b>: ".$session_status.'</li>'; // echo "</ul></div>"; if(isset($_COOKIE['user_id'])) { echo '<div class="message">You are currently logged in using cookies. Please <a href="index.php?chapter=12&script=12.6&path=using+cookies" title="Logout from cookies">log out</a> if you would like to login as a different user.</div>'; } elseif(isset($_SESSION['user_id'])) { echo '<div class="message">You are currently logged in using sessions. Please <a href="index.php?chapter=12&script=12.11&path=using+sessions" title="Logout from sessions">log out</a> if you would like to login as a different user.</div>'; }else { // Display the form // Print any error messages, if they exist: if (isset($errors) && !empty($errors)) { echo '<div class="message">'; echo '<h1>Error!</h1>'; echo '<p class="error">'; echo (isset($errors['m']) && !empty($errors['m']))? $errors['m'] .'<br />': ''; echo 'You could not be logged in.<br />Please try again.</p></div>'; } ?> <h1>Login</h1> <script type="text/javascript"> var cookies = are_cookies_enabled(); if(cookies == false) { document.write("<div class='message'><span class='error'>You have cookies turned off. Cookies must be enabled for login functionality.</span></div>"); } </script> <form action="<?php echo htmlentities( $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'] ); ?>" method="post"> <div>For testing purposes: <br />Email address = test@mail.com <br />Password = 1234</div> <p> <label for="e">Email Address: </label> <input id="e" type="text" name="email" size="20" maxlength="60" value="<?php echo (isset($email) && $email != '')? $email : ''; ?>"/> <?php echo (isset($errors['e']) && !empty($errors['e']))? '<span class="error">'.$errors['e'] .'</span>' : ''; ?> </p> <p> <label for="p">Password: </label> <input id="p" type="password" name="pass" size="20" maxlength="20" /> <?php echo (isset($errors['p']) && !empty($errors['p']))? '<span class="error">'.$errors['p'] .'</span>' : ''; ?> </p> <p> <input type="submit" name="submit" value="Login" /> </p> </form> <?php } echo "</div>"; include (CHAPTER_PATH.'/'.$chapter.'/includes/footer.php'); ?>