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 191698 2005-07-28 11:21:32Z lsmith $
  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. ?>
  26. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  27. <html>
  28. <head>
  29.     <title>Example 2</title>
  30.     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  31.     <style type="text/css">
  32.     <!--
  33.     body {
  34.         font-family: Verdana, Arial, Helvetica, sans-serif;
  35.         font-size: 12px;
  36.         color: #000000;
  37.         background-color: #FFFFFF
  38.     }
  39.  
  40.     table {
  41.         border: 1px solid #000;
  42.         border-top: 0px;
  43.         border-right: 0px;
  44.         border-spacing: 0px;
  45.         border-collapse: collapse;
  46.     }
  47.  
  48.     table td {
  49.         width: 100px;
  50.         border-top: 1px solid #000;
  51.         border-right: 1px solid #000;
  52.         padding: 5px;
  53.     }
  54.  
  55.         .center {
  56.            text-align: center;
  57.     }
  58.     .center table {
  59.            margin: auto;
  60.     }
  61.     -->
  62.     </style>
  63. </head>
  64.  
  65. <body>
  66. <?php
  67. // Check if the user has logged in successfully
  68. if (!$LU->isLoggedIn()) {
  69.     if (!empty($_REQUEST)) {
  70. ?>
  71.     <form name="loginform" method="post" action="example.php">
  72.     <div class="center">
  73.         <table width="300" border="0" cellspacing="0" cellpadding="5">
  74.             <tr>
  75.                 <td colspan="2"><b>Example login</b></td>
  76.             </tr>
  77.             <tr>
  78.                 <td>Handle:</td>
  79.                 <td>
  80.                     <input type="text" name="handle" maxlength="80" value="" />
  81.                 </td>
  82.             </tr>
  83.              <tr>
  84.                 <td>Password:</td>
  85.                 <td>
  86.                     <input type="password" name="password" maxlength="80" value="" />
  87.                 </td>
  88.             </tr>
  89.             <tr>
  90.                 <td>Remember me:</td>
  91.                 <td>
  92.                     <input type="checkbox" name="remember" value="1" />
  93.                 </td>
  94.             </tr>
  95.             <tr>
  96.                 <td colspan="2">
  97.                     <div class="center">
  98.                         <input type="submit" value="Login" />
  99.                     </div>
  100.                 </td>
  101.             </tr>
  102.         </table>
  103.     </div>
  104.     </form>
  105. <?php
  106.     // The user couldn't login, so let's check if the reason was that
  107.     // he's not yet been declared "valid" by an administrator.
  108.     else if ($LU->isInactive()) {
  109. ?>
  110.         <h3>Sorry kid, but one of our admins has yet approved
  111.        your user status. Please be patient. Don't call us -
  112.        we'll call you.</h3>
  113.       <p align="center"><a href="example.php?logout=1">Logout</a></p>
  114. <?php
  115.     else {
  116. ?>
  117.       <h3>Sorry, we can't let you in. Check if the spelling of
  118.       your handle and password is correct.</h3>
  119.       <p align="center"><a href="example.php?logout=1">Logout</a></p>
  120. <?php
  121.     }
  122. ?>
  123.         <p>&nbsp;</p>
  124.         <p><i>Login Data for this Example:</i></p>
  125.         <table>
  126.             <tr>
  127.                 <td style="text-align: center; font-weight: bold;">Handle</th>
  128.                 <td style="text-align: center; font-weight: bold;">Password</th>
  129.             </tr>
  130.             <tr>
  131.             <td>father</td>
  132.                 <td>father</td>
  133.             </tr>
  134.             <tr>
  135.             <td>mother</td>
  136.                 <td>mother</td>
  137.             </tr>
  138.             <tr>
  139.                 <td>child</td>
  140.                 <td>child</td>
  141.     </tr>
  142.     </table>
  143. <?php
  144. else {
  145. ?>
  146.     <div class="center">
  147.         <h2 style="text-align: center;">User logged in: <?php echo $LU->getProperty('handle')?></h2>
  148.         <p>You can see user's rights in the table.</p>
  149.         <table class="info">
  150.             <tr>
  151.                 <td>right / room</td>
  152.                 <td>kitchen</td>
  153.                 <td>livingroom</td>
  154.                 <td>office</td>
  155.             </tr>
  156. <?php
  157.       //Let's check the rights in the kitchen.
  158. ?>
  159.             <tr>
  160.                 <td>cooking</td>
  161. <?php
  162.     // check whether the user has the required right
  163.     if ($LU->checkRight(COOKING)) {
  164. ?>
  165.                 <td>X</td>
  166. <?php
  167.     else {
  168. ?>
  169.                 <td>&nbsp;</td>
  170. <?php
  171.     }
  172. ?>
  173.                 <td>&nbsp;</td>
  174.                 <td>&nbsp;</td>
  175.             </tr>
  176.             <tr>
  177.                 <td>wash the dishes</td>
  178. <?php
  179.     // check whether the user has the required right
  180.     if ($LU->checkRight(WASHTHEDISHES)) {
  181. ?>
  182.             <td>X</td>
  183. <?php
  184.     else {
  185. ?>
  186.                 <td>&nbsp;</td>
  187. <?php
  188.     }
  189. ?>
  190.                 <td>&nbsp;</td>
  191.                 <td>&nbsp;</td>
  192.             </tr>
  193. <?php
  194.         //Let's check the rights in the livingroom.
  195. ?>
  196.             <tr>
  197.                 <td>watch TV</td>
  198.                 <td>&nbsp;</td>
  199. <?php
  200.     // check whether the user has the required right
  201.     if ($LU->checkRight(WATCHTV)) {
  202. ?>
  203.                 <td>X</td>
  204. <?php
  205.     else {
  206. ?>
  207.                  <td>&nbsp;</td>
  208. <?php
  209.     }
  210. ?>
  211.                 <td>&nbsp;</td>
  212.             </tr>
  213.             <tr>
  214.                 <td>watch latenight TV</td>
  215.                 <td>&nbsp;</td>
  216. <?php
  217.     // check whether the user has the required right
  218.     if ($LU->checkRight(WATCHLATENIGHTTV)) {
  219. ?>
  220.                 <td>X</td>
  221. <?php
  222.     else {
  223. ?>
  224.                 <td>&nbsp;</td>
  225. <?php
  226.     }
  227. ?>
  228.                 <td>&nbsp;</td>
  229.             </tr>
  230. <?php
  231.     //Let's check the rights in the office.
  232. ?>
  233.             <tr>
  234.                 <td>use the computer</td>
  235.                 <td>&nbsp;</td>
  236.                 <td>&nbsp;</td>
  237. <?php
  238.     // check whether the user has the required right
  239.     if ($LU->checkRight(USETHECOMPUTER)) {
  240. ?>
  241.                 <td>X</td>
  242. <?php
  243.     else {
  244. ?>
  245.                 <td>&nbsp;</td>
  246. <?php
  247.     }
  248. ?>
  249.             </tr>
  250.             <tr>
  251.                 <td>connecting to the internet</td>
  252.                 <td>&nbsp;</td>
  253.                 <td>&nbsp;</td>
  254. <?php
  255.     // check whether the user has the required right
  256.     if ($LU->checkRight(CONNECTINGTHEINTERNET)) {
  257. ?>
  258.                 <td>X</td>
  259. <?php
  260.     else {
  261. ?>
  262.                 <td>&nbsp;</td>
  263. <?php
  264.     }
  265. ?>
  266.             </tr>
  267.         </table>
  268.     </div>
  269.     <p align="center"><a href="example.php?logout=1">Logout</a></p>
  270. <?php
  271. }
  272. // Just some more debug output with no further relevance
  273. echo '<hr />Handle:';
  274. print_r($LU->getProperty('handle'));
  275. echo '<br />User Type:';
  276. print_r($LU->getProperty('perm_type'));
  277.  
  278. echo '<hr /><pre>';
  279. print_r($LU);
  280. echo '<hr />';
  281. print_r($_SESSION);
  282. echo '<hr />';
  283. print_r($_REQUEST);
  284. echo '</pre>';
  285. ?>
  286. </body>
  287. </html>

Documentation generated on Mon, 11 Mar 2019 15:40:12 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.