PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of David Duong   Usermanage   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Simple example of usermanage in action
Class: Usermanage
Puzzle like modular authentication class
Author: By
Last change:
Date: 20 years ago
Size: 11,207 bytes
 

Contents

Class file image Download
<?php // ---------------------------------------------------------------------- // LEMP - Lightweight Efficient Modular PHP Application Framework // @copyright 2002-2003 The CGI Open Source Federation. (http://cosf.sf.net) // @version $Id: index.php,v 1.26 2004/03/09 00:29:31 cogs Exp $ // ---------------------------------------------------------------------- // LICENSE // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License (GPL) // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have recieved the lincence included with the disribution. // If not visit http://www.gnu.org/copyleft/gpl.html // ---------------------------------------------------------------------- // Open Demo 1 // // This is just a demo and should not be used in your application. // ie) You sould not check if necessary database tables have been created // in the index.php file, or should you have a member's area and login together // in index.php. // ---------------------------------------------------------------------- require ('LEMP/lemp.php'); // Point this to lemp.php $auth = &create_obj (); // Create the object // Determine if necessary database tables have been created. $tables = get_config ('tables', 'auth_user_info'); $result = $auth->dbquery ("SHOW TABLES LIKE '{$tables['_name']}';"); if (!$result) { error_add ('DB Error, could not list tables'); exit (error_get_all(LEMP_HTML)); } elseif ($auth->dbnum_rows ($result) == 0) { exit ('You have not set up the tables User Manage needs to run! (Most likely someone has tried the uninstall feature of our demo, installation is a simple process, just <a href="setup.php">Click Here to Install</a>)'); } // Determine code flow if (isset ($auth->in['action'])) { switch($auth->in['action']) { case 'Login': $mode = ($auth->in['Remember'])? 'persistent': 'normal'; $ret = $auth->login ($auth->in['UserName'], $auth->in['Password'], $mode); break; case 'Logout': $ret = $auth->logout(); break; case 'Join': $ret = $auth->create_user ($auth->in['uname'], $auth->in['password'], $auth->in['conf_password']); break; } // If there are no errors continue... if ($ret) { header ("Location: "); // Refresh to make cookie visible exit(); } } // If they have access // You can use $auth->verify_session() for extra security if ($auth->access > 0) { ?> <html> <head> <title>User Manage</title> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <meta http-equiv="CACHE-CONTROL" content="NO-CACHE"> <meta name="expires" content="1 January 2000"> <meta name="robots" content="noindex,nofollow"> </head> <body topmargin=1 leftmargin=1 rightmargin=0> <center> &nbsp;Cookie Set = <font color='red'><?php echo $auth->authok; ?></font><br> <table width=500 bgcolor='#3366CC' border=1 style="border-collapse: collapse" bordercolor="#C0C0C0" cellpadding="0" cellspacing="0"> <th bgcolor="#3366CC"> <font color="#FFFFFF">Open Demo 1 (index)</font> </th> <tr> <td bgcolor="#3586FF"> You have successfully logged in, and a new session has been set. To keep pages private you must add the following code into your php script: <table bgcolor="#FFFFFF" border='1' bordercolor="#000000"> <tr> <td NORAP> <?php $example_txt = <<<EOL <?php include ('LEMP/lemp.php'); // Point this to lemp.php $auth = &create_obj (); // Create the object if ({$auth->access} <= 0) { // Check the user's login status error_add(AUTH_NOT_LOGED_IN); // Add error to log echo error_get_all (); // Display all errors exit (); // Terminate script } ?> EOL; highlight_string ($example_txt); ?> </td> </tr> </span> <br> If you click Logout below, you will no longer see this, even though it is the same index.php file. The cookie will be erased so you will need to re-login to access this page. </td> </tr> </table> <p align='center'> <textarea cols=80 rows=25> <?php // Demo for some auth properties: echo <<<EOL To get user information use the following variables: For user id = \$auth->uid: {$auth->uid} For user name = \$auth->uname: {$auth->uname} For user pass ** = \$auth->pass: {$auth->pass} For session (db *) = \$auth->sid: {$auth->sid} For session (client *) = \$auth->authok: {$auth->authok} *User session (db) is the copy stored on database, User session (client) is the copy stored inside a cookie on the user's machine. **Passwords are encrypted with md5 encryption for maximum security. EOL; ?></textarea> <p><a href='http://usermanage.sourceforge.net/docs/'>More Info</a> | <a href='index.php?action=Logout'>Logout</a> | <a href='setup.php'>Un-install</a> <?php // For usermanage demos at http://usermanage.sourceforge.net/, // but if a next_step.php exists we will create a link to it if (file_exists('next_step.php')) echo "| <a href='next_step.php'>Next Step --></a>"; ?></p> <?php } else { ?> <html> <head> <title>User Manage</title> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <meta http-equiv="Cache-Control" content="No-Cache"> <meta http-equiv="Pragma" content="no-cache"> <meta name="expires" content="1 January 2000"> <meta name="robots" content="noindex,nofollow"> </head> <body topmargin=1 leftmargin=1 rightmargin=0> <center> <?php // If user clicked 'create login' then show the create login box if ($auth->in['create_login'] == "true") { ?> <p align="center"><a href='index.php'>Login</a></p> <table border='0' bgcolor='#ffffff' align='center'> <form action='index.php' method='post'> <input type="hidden" name="action" value="Join"> <th colspan='2' bgcolor='#0e00b2' style="border-style: solid; border-width: 1"> <font color='#ffffff'> Join Usermanage </font> </th> <tr> <td style="border-left-style: solid; border-left-width: 1; border-right-style: solid; border-right-width: 1; border-top-style: solid; border-top-width: 1">Username </td> <td style="border-left-style: solid; border-left-width: 1; border-right-style: solid; border-right-width: 1"> <input type='text' name='uname' size="20"></td> </tr> <tr> <td style="border-left-style: solid; border-left-width: 1; border-right-style: solid; border-right-width: 1">Password</td> <td style="border-left-style: solid; border-left-width: 1; border-right-style: solid; border-right-width: 1"> <input type='password' name='password' size="20"></td> </tr> <tr> <td style="border-left-style: solid; border-left-width: 1; border-right-style: solid; border-right-width: 1; border-bottom-style: solid; border-bottom-width: 1">Confirm Password</td> <td style="border-left-style: solid; border-left-width: 1; border-right-style: solid; border-right-width: 1; border-bottom-style: none; border-bottom-width: medium"> <input type='password' name='conf_password' size="20"></td> </tr> <tr> <td colspan='2' align='right' style="border-left-style: solid; border-left-width: 1; border-right-style: solid; border-right-width: 1; border-bottom-style: solid; border-bottom-width: 1"><input type='submit' name='Join' value='Create'></td> </tr> </form> </table> <?php // If user did not click create login than show them the login box } else { ?> <p align="center"><a href='index.php?create_login=true'>Join</a></p> <table border='0' bgcolor='#ffffff' align=center> <form action='index.php' method='post'> <input type="hidden" name="action" value="Login"> <th colspan='2' bgcolor='#oeoob2' style="border-left-style: solid; border-left-width: 1; border-right-style: solid; border-right-width: 1; border-top-style: solid; border-top-width: 1"> <font color='#ffffff'>Usermanage login</font> </th> <tr> <td style="border-left-style: solid; border-left-width: 1">Username </td> <td style="border-right-style: solid; border-right-width: 1; border-top-style: solid; border-top-width: 1"><input type='text' name='UserName' size="20"></td> </tr> <tr> <td style="border-left-style: solid; border-left-width: 1">Password</td> <td style="border-right-style: solid; border-right-width: 1; border-bottom-style: solid; border-bottom-width: 1"><input type='password' name='Password' size="20"></td> </tr> <tr> <td style="border-left-style: solid; border-left-width: 1">Remember Me</td> <td style="border-right-style: solid; border-right-width: 1; border-bottom-style: solid; border-bottom-width: 1"><input type='checkbox' name='Remember'></td> </tr> <tr> <td colspan='2' align='right' style="border-left-style: solid; border-left-width: 1; border-right-style: solid; border-right-width: 1; border-bottom-style: solid; border-bottom-width: 1"><input type='submit' name='Login' value='Login'></td> </tr> </form> </table> <?php } } // Display all errors at bottom of page ?> <br> Messages: <?php echo error_get_all(LEMP_HTML); ?> </center> </body> <html>