Advertisement
Guest User

Untitled

a guest
Jun 13th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. <?php
  2. session_start();
  3. if(isset($_GET['logout'])) {
  4. unset($_SESSION['isAdmin']);
  5. $redirectUrl = "index.php";
  6. $redirectMessage = <<<ENDL
  7. Выход.
  8. Нажмите на ссылку, если Ваш браузер не поддерживает перенаправление:
  9. <a href="{$redirectUrl}">Вернуться</a>.
  10. ENDL;
  11. header("Location: {$redirectUrl}");
  12. include WEB_ROOT.'/lib/redirect.php';
  13. exit;
  14. }
  15.  
  16. if($_SESSION['isAdmin']) {
  17. $redirectUrl = "index.php";
  18. $redirectMessage = <<<ENDL
  19. Вы уже вошли.
  20. Нажмите на ссылку, если Ваш браузер не поддерживает перенаправление:
  21. <a href="{$redirectUrl}">Вернуться</a>.
  22. ENDL;
  23. header("Location: {$redirectUrl}");
  24. include WEB_ROOT.'/lib/redirect.php';
  25. exit;
  26. }
  27.  
  28. if (!defined("WEB_ROOT")) {
  29. define("WEB_ROOT", realpath(dirname(__FILE__)."/./"));
  30. }
  31. require_once WEB_ROOT.'/config/config.php';
  32. require_once WEB_ROOT.'/lib/HTML/FormPersister.php';
  33. ob_start(array('HTML_FormPersister', 'ob_formpersisterhandler'));
  34.  
  35. $errors = array();
  36. if(isset($_POST['doSend'])) {
  37. $user = array();
  38. if(!isset($_POST['login']) || empty($_POST['login'])) {
  39. $errors['login'] = "Данное поле должно быть заполнено!";
  40. }
  41. else {
  42. $user['login'] = $_POST['login'];
  43. }
  44. if(!isset($_POST['pass']) || empty($_POST['pass'])) {
  45. $errors['pass'] = "Данное поле должно быть заполнено!";
  46. }
  47. else {
  48. $user['pass'] = $_POST['pass'];
  49. }
  50. if(empty($errors)) {
  51. $userId = $DATABASE->selectCell(
  52. 'SELECT id FROM ?_users WHERE name=? AND pass=? AND is_admin = 1', $user['login'], md5($user['pass'])
  53. );
  54. if(empty($userId)) {
  55. $errors['common'] = "Пользователь с такими данными не существует!";
  56. }
  57. else {
  58. $_SESSION['isAdmin'] = $userId;
  59. $redirectUrl = "index.php";
  60. $redirectMessage = <<<ENDL
  61. Вы успешно вошли.
  62. Нажмите на ссылку, если Ваш браузер не поддерживает перенаправление:
  63. <a href="{$redirectUrl}">Вернуться</a>.
  64. ENDL;
  65. header("Location: {$redirectUrl}");
  66. include WEB_ROOT.'/lib/redirect.php';
  67. exit;
  68. }
  69. }
  70. unset($_POST['pass']);
  71. }
  72. ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  73. <html>
  74. <head>
  75. <meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
  76. <title><?php echo PROJECTNAME; ?></title>
  77. <link rel="stylesheet" type="text/css" href="css/main.css" media="screen" />
  78. </head>
  79. <body class="main_body">
  80. <?php if(isset($errors['common'])) : ?>
  81. <div class="errors"><?php echo htmlspecialchars($errors['common']); ?></div>
  82. <?php endif; ?>
  83. <form method="post">
  84. <table align="center" width="300" cellpadding="0" cellspacing="1" bgcolor="#cccccc" border="0" class="t_films">
  85. <tr>
  86. <td width="30%">
  87. Логин:
  88. </td>
  89. <td>
  90. <input type="text" maxlength="50" name="login" class="i_login" />
  91. <?php if(isset($errors['login'])) : ?>
  92. <div class="errors"><?php echo htmlspecialchars($errors['login']); ?></div>
  93. <?php endif; ?>
  94. </td>
  95. </tr>
  96. <tr>
  97. <td>
  98. Пароль:
  99. </td>
  100. <td>
  101. <input type="password" maxlength="50" name="pass" class="i_pass" />
  102. <?php if(isset($errors['pass'])) : ?>
  103. <div class="errors"><?php echo htmlspecialchars($errors['pass']); ?></div>
  104. <?php endif; ?>
  105. </td>
  106. </tr>
  107. <tr><td>&nbsp;</td><td><input type="submit" name="doSend" value="Войти" /></td></tr>
  108. </table>
  109. </form>
  110. </body>
  111. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement