login_session_auth.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. // Some settings
  3. $msg = "";
  4. $username = "demo";
  5. $password = "demo"; // Change the password to something suitable
  6. if (!$password)
  7. $msg = 'You must set a password in the file "login_session_auth.php" inorder to login using this page or reconfigure it the authenticator config options to fit your needs. Consult the <a href="http://wiki.moxiecode.com/index.php/Main_Page" target="_blank">Wiki</a> for more details.';
  8. if (isset($_POST['submit_button'])) {
  9. // If password match, then set login
  10. if ($_POST['login'] == $username && $_POST['password'] == $password && $password) {
  11. // Set session
  12. session_start();
  13. $_SESSION['isLoggedIn'] = true;
  14. $_SESSION['user'] = $_POST['login'];
  15. // Override any config option
  16. //$_SESSION['imagemanager.filesystem.rootpath'] = 'some path';
  17. //$_SESSION['filemanager.filesystem.rootpath'] = 'some path';
  18. // Redirect
  19. header("location: " . $_POST['return_url']);
  20. die;
  21. } else
  22. $msg = "Wrong username/password.";
  23. }
  24. ?>
  25. <html>
  26. <head>
  27. <title>Sample login page</title>
  28. <style>
  29. body { font-family: Arial, Verdana; font-size: 11px; }
  30. fieldset { display: block; width: 170px; }
  31. legend { font-weight: bold; }
  32. label { display: block; }
  33. div { margin-bottom: 10px; }
  34. div.last { margin: 0; }
  35. div.container { position: absolute; top: 50%; left: 50%; margin: -100px 0 0 -85px; }
  36. h1 { font-size: 14px; }
  37. .button { border: 1px solid gray; font-family: Arial, Verdana; font-size: 11px; }
  38. .error { color: red; margin: 0; margin-top: 10px; }
  39. </style>
  40. </head>
  41. <body>
  42. <div class="container">
  43. <form action="login_session_auth.php" method="post">
  44. <input type="hidden" name="return_url" value="<?php echo isset($_REQUEST['return_url']) ? htmlentities($_REQUEST['return_url']) : ""; ?>" />
  45. <fieldset>
  46. <legend>Example login</legend>
  47. <div>
  48. <label>Username:</label>
  49. <input type="text" name="login" class="text" value="<?php echo isset($_POST['login']) ? htmlentities($_POST['login']) : ""; ?>" />
  50. </div>
  51. <div>
  52. <label>Password:</label>
  53. <input type="password" name="password" class="text" value="<?php echo isset($_POST['password']) ? htmlentities($_POST['password']) : ""; ?>" />
  54. </div>
  55. <div class="last">
  56. <input type="submit" name="submit_button" value="Login" class="button" />
  57. </div>
  58. <?php if ($msg) { ?>
  59. <div class="error">
  60. <?php echo $msg; ?>
  61. </div>
  62. <?php } ?>
  63. </fieldset>
  64. </form>
  65. </div>
  66. </body>
  67. </html>