Advertisement
Guest User

Untitled

a guest
Jan 21st, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. header('Content-type: text/html; charset=utf-8');
  3. error_reporting(E_ALL);
  4. session_start();
  5. $users = array('stas' => '40bd001563085fc35165329ea1ff5c5ecbdbbeef');
  6.  
  7. $codes = unserialize(file_get_contents('touch.txt');
  8.  
  9.  
  10. if(empty($_SESSION['username']))
  11. {
  12.     if(empty($_POST['ok']))
  13.     {
  14.         $content = '<label>Логин<input name="username"></label><br>
  15.                    <label>Пароль<input type="password" name="password"></label><br>
  16.                    <input type="submit" name="ok" value="чикинимся">';
  17.     }
  18.     else
  19.     {
  20.         foreach($users as $username => $password)
  21.             if($username == $_POST['username'] && $password == sha1($_POST['password']))
  22.                 $_SESSION['username'] = $username;
  23.  
  24.         if(empty($_SESSION['username']))
  25.         {
  26.             header('HTTP/1.1 404 Not Found');
  27.             die('404');
  28.         }
  29.         else
  30.             header('location: ' . $_SERVER['HTTP_REFERER']);
  31.     }
  32. }
  33. else
  34. {
  35.     if(!empty($_POST['leave']))
  36.     {
  37.         session_unset();
  38.         session_destroy();
  39.         header('location: ' . $_SERVER['HTTP_REFERER']);
  40.     }
  41.     if(empty($_POST['role']))
  42.     {
  43.         $content = 'Welcome home, ' . $_SESSION['username'] . '! Choose your fate<br>
  44.                    <input type="submit" name="role" value="admin">&nbsp
  45.                    <input type="submit" name="role" value="student">&nbsp
  46.                    <input type="submit" name="role" value="teacher">&nbsp';
  47.     }
  48.     else
  49.     {
  50.         if(!empty($_POST['code']) && !empty($_POST['role']) && array_key_exists($_POST['role'], $codes))
  51.         {
  52.             if($codes[$_POST['role']] == sha1($_POST['code']))
  53.                 $content = '42';
  54.             else
  55.             {
  56.                 header('HTTP/1.1 404 Not Found');
  57.                 die('404');
  58.             }
  59.         }
  60.         else
  61.         {
  62.             $content = 'Введите пароль<br>
  63.                        <input type="password" name="code">
  64.                        <input type="hidden" name="role" value="' . $_POST['role'] . '">
  65.                        <input type="submit" name="ok" value="чикин">';
  66.         }
  67.     }
  68.     $content .= '<input type="submit" name="leave" value="все по новой" style="position: absolute; right: 0; top: 0">';
  69. }
  70. ?>
  71. <!DOCTYPE html>
  72. <html>
  73. <head>
  74.     <title>Стас<333</title>
  75. </head>
  76. <body style="text-align: center; padding-top: 200px">
  77.     <form action="" method="post">
  78.         <?php echo $content; ?>
  79.     </form>
  80. </body>
  81. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement