LiveUser
[ class tree: LiveUser ] [ index: LiveUser ] [ all elements ]

Source for file example.php

Documentation is available at example.php

  1. <?php
  2. /**
  3.  * Test for the LiveUser class
  4.  * ===============================
  5.  *
  6.  * This example sets up an authorization system using the LiveUser
  7.  * class. You don't have to use this to use the LiveUser class(es), but
  8.  * this way you don't need to take care of the login-process, storing
  9.  * the user object in a session and more...
  10.  *
  11.  * This example is intended to be used with the auth XML driver.
  12.  * No permission management is supported.
  13.  *
  14.  * @author
  15.  * @version $Id: example.php,v 1.8 2004/04/27 00:25:23 mscifo Exp $
  16.  ***/
  17.  
  18. // Get LiveUser configuration array
  19. require_once 'conf.php';
  20.  
  21. if ($xml_is_readable == false || $xml_is_writable == false{
  22.     die('<p style="color: red; text-align: center;">The XML file isn\'t readable/writable. Add the right permissions to it and then try again.</p>');
  23. }
  24.  
  25. // The error handling stuff is not needed and used only for debugging
  26. // while LiveUser is not yet mature
  27. PEAR::setErrorHandling(PEAR_ERROR_CALLBACK'eHandler');
  28.  
  29. function eHandler($errObj)
  30. {
  31.     echo('<hr /><span style="color: red">' $errObj->getMessage(':<br />'$errObj->getUserinfo('</span><hr />');
  32. }
  33.  
  34. // Create new LiveUser (LiveUser) object.
  35. $LU =LiveUser::factory($liveuserConfig);
  36.  
  37. $username (isset($_REQUEST['handle'])) $_REQUEST['handle': NULL;
  38. $password (isset($_REQUEST['passwd'])) $_REQUEST['passwd': NULL;
  39. $logout (isset($_REQUEST['logout'])) $_REQUEST['logout': FALSE;
  40. $LU->init($username$password$logout);
  41. ?>
  42. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  43. <html>
  44. <head>
  45.     <title>Example 1</title>
  46.     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  47.     <style type="text/css">
  48.     <!--
  49.     body {
  50.         font-family: Verdana, Arial, Helvetica, sans-serif;
  51.         font-size: 12px;
  52.         color: #000000;
  53.         background-color: #FFFFFF
  54.     }
  55.  
  56.     table {
  57.         border: 1px solid #000;
  58.         border-top: 0px;
  59.         border-right: 0px;
  60.         border-spacing: 0px;
  61.         border-collapse: collapse;
  62.     }
  63.  
  64.     table td {
  65.         width: 100px;
  66.         border-top: 1px solid #000;
  67.         border-right: 1px solid #000;
  68.         padding: 5px;
  69.     }
  70.  
  71.         .center {
  72.            text-align: center;
  73.     }
  74.     .center table {
  75.            margin: auto;
  76.     }
  77.     -->
  78.     </style>
  79. </head>
  80.  
  81. <body>
  82. <?php
  83. // Check if the user has logged in successfully
  84. if (!$LU->isLoggedIn()) {
  85.     if (!$username{
  86. ?>
  87.     <form name="loginform" method="post" action="example.php">
  88.     <div class="center">
  89.         <table width="300" border="0" cellspacing="0" cellpadding="5">
  90.             <tr>
  91.                 <td colspan="2"><b>Example login</b></td>
  92.             </tr>
  93.             <tr>
  94.                 <td>Handle:</td>
  95.                 <td>
  96.                     <input type="text" name="handle" maxlength="80" value="" />
  97.                 </td>
  98.             </tr>
  99.              <tr>
  100.                 <td>Password:</td>
  101.                 <td>
  102.                     <input type="password" name="passwd" maxlength="80" value="" />
  103.                 </td>
  104.             </tr>
  105.             <tr>
  106.                 <td colspan="2">
  107.                     <div class="center">
  108.                         <input type="submit" value="Login" />
  109.                     </div>
  110.                 </td>
  111.             </tr>
  112.         </table>
  113.     </div>
  114.     </form>
  115. <?php
  116.     // The user couldn't login, so let's check if the reason was that
  117.     // he's not yet been declared "valid" by an administrator.
  118.     else if ($LU->isInactive()) {
  119. ?>
  120.         <h3>Sorry kid, but one of our admins has yet approved
  121.        your user status. Please be patient. Don't call us -
  122.        we'll call you.</h3>
  123.       <p align="center"><a href="example.php?logout=1">Logout</a></p>
  124. <?php
  125.     else {
  126. ?>
  127.       <h3>Sorry, we can't let you in. Check if the spelling of
  128.       your handle and password is correct.</h3>
  129.       <p align="center"><a href="example.php?logout=1">Logout</a></p>
  130. <?php
  131.     }
  132. ?>
  133.         <p>&nbsp;</p>
  134.         <p><i>Login Data for this Example:</i></p>
  135.         <table>
  136.             <tr>
  137.                 <td style="text-align: center; font-weight: bold;">Handle</th>
  138.                 <td style="text-align: center; font-weight: bold;">Password</th>
  139.             </tr>
  140.             <tr>
  141.             <td>father</td>
  142.                 <td>father</td>
  143.             </tr>
  144.             <tr>
  145.             <td>mother</td>
  146.                 <td>mother</td>
  147.             </tr>
  148.             <tr>
  149.                 <td>child</td>
  150.                 <td>child</td>
  151.     </tr>
  152.     </table>
  153. <?php
  154. else {
  155. ?>
  156.     <h2 align="center">User logged in: <?php echo $LU->getProperty('handle')?></h2>
  157.     <h3>Congrats, you're in</h3>
  158.     <p align="center"><a href="example.php?logout=1">Logout</a></p>
  159. <?php
  160. }
  161. // Just some more debug output with no further relevance
  162. echo '<hr />Handle:';
  163. print_r($LU->getProperty('handle'));
  164. echo '<br />User Type:';
  165. print_r($LU->getProperty('userType'));
  166.  
  167. echo '<hr /><pre>';
  168. print_r($LU);
  169. echo '<hr />';
  170. print_r($_SESSION);
  171. echo '<hr />';
  172. print_r($_REQUEST);
  173. echo '</pre>';
  174. ?>
  175. </body>
  176. </html>

Documentation generated on Mon, 11 Mar 2019 13:56:17 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.