Documentation is available at login.php
- <?php
- /**
- * Login Script
- *
- * Validates the login form, authenticates the user and
- * stores the user information in session variables
- * @package Phone2Dev
- * @author Stanislav Miroshnikov
- * @todo add template support
- */
- //start the session
- session_start();
- ?>
- <html>
- <head>
- <title>Phone2Dev Login</title>
- </head>
- <body>
- <h1>Phone2Dev</h1>
- <?php
- /**
- * Requires PEAR HTML_QuickForm package
- */
- require_once 'HTML/QuickForm.php';
- $form =& new HTML_QuickForm();
- $form->addElement('header','userInfo','Login');
- // username
- $form->addElement('text', 'username', 'Username: ');
- // "required" rule
- $form->addRule('username','Please enter your username.', 'required');
- // "maxlength" rule
- $form->addRule('username'
- ,'Please enter a username between 3 and 30 characters.',
- 'rangelength',array(3, 30));
- // "alphanumeric" rule
- $form->addRule('username'
- ,'Your username can contain only letters and numbers.'
- , 'alphanumeric');
- // passwords
- $form->addElement('password','password','Password:');
- // "required" rule
- $form->addRule('password','Please enter your password.', 'required');
- // "maxlength" rule
- $form->addRule('password'
- ,'Please enter a password between 6 and 12 characters.',
- 'rangelength', array(6, 12));
- // "alphanumeric" rule
- $form->addRule('password'
- ,'Your password can contain only letters and numbers.'
- , 'alphanumeric');
- $form->addElement('submit', 'login', 'Login');
- $form->applyFilter('__ALL__', 'trim');
- if ($form->validate()) {
- // If the form validates, freeze and process the data
- $form->freeze();
- $form->process('login');
- } else {
- $form->display();
- }
- /**
- * Authenticates the user
- * @param fields an associative array containing fields of the form
- * @todo login attempts counter
- * @todo a more secure way of keeping track of the user
- * that includes keeping track of user's IP address
- */
- function login($fields) {
- /**
- * Requires Phone2Dev class for database access
- */
- require_once 'phone2dev.php';
- $objP2D = &new Phone2Dev();
- // connect to the database
- $objP2D->dbConnect();
- // check if the username and password are correct
- $intUserId = $objP2D->authUserPass($fields['username'],
- $fields['password']);
- if($intUserId > 0) {
- // user was autheticated correctly
- // set the user's session variables
- $_SESSION['intUserId'] = $intUserId;
- $_SESSION['intMainMenuId'] = $objP2D->getMainMenuId($intUserId);
- $_SESSION['strUsername'] = $fields['username'];
- // redirect user to the main manu
- header("Location: http://" . $_SERVER['HTTP_HOST']
- . dirname($_SERVER['PHP_SELF'])
- . "/" . "menu.php");
- } else {
- // user have not authenticated correctly
- print "<h1>Login Error</h1>";
- print "<h2>Your username and/or password is invalid.</h2>";
- print "<p><a href=\"login.php\">Try Again</a></p>";
- }
- }
- ?>
- <p> Register for Phone2Dev <a href="register.php">here</a>.</p>
- </body>
- </html>
Documentation generated on Tue, 4 Jan 2005 13:47:59 -0500 by phpDocumentor 1.3.0RC3