Script 17.9
PHP and MySQL for Dynamic Web Sites: The Forum!
English/English
Login
<?php # Script 17.9 - login using sessions // This page processes the login form submission. // The script now uses sessions. if($_SERVER['REQUEST_METHOD'] == 'POST') { // For processing the login: require (CHAPTER_PATH.'/'.$chapter.'/includes/17.13.php'); // Need the database connection: require (CONNECT_OOP); // Check the login: list ($check, $data) = check_forum_login($link, $_POST['user_name'], $_POST['pass']); require(DISCONNECT_OOP); // Close the database connection. if ($check) { // OK! // Set the session data: $_SESSION['user_id'] = $data['user_id']; $_SESSION['user_name'] = $data['username']; $_SESSION['lid'] = $data['lang_id']; $_SESSION['tz'] = $data['time_zone']; if(isset($_SESSION['errors'])) { unset($_SESSION['errors']); } // Redirect user to login confirmation page redirect_user('index.php?chapter=17&script=17.10'); } else { // Unsuccessful -redirect user to same page storing any errors in a session to be processed in the form // Assign $data to $errors for login_page.inc.php: $errors = $data; $_SESSION['errors'] = $data; $_SESSION['user_name'] = $_POST['user_name']; redirect_user('index.php?chapter=17&script=17.9'); } } // End of the main submit conditional. // Create the page: include (CHAPTER_PATH.'/'.$chapter.'/17.12.php'); ?>