Advertisement
Arsylk

Narkoman Incorporated

Nov 18th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.37 KB | None | 0 0
  1. <?php
  2. header('Cache-Control: no-cache, must-revalidate');
  3. ?>
  4.  
  5.  
  6. <?php
  7. session_name('login');
  8. session_start();
  9.  
  10. // handle forms
  11. if(isset($_POST['action'])) {
  12.  
  13.   // login form
  14.   if($_POST['action'] == 'login') {
  15.     if(isset($_POST['username']) && isset($_POST['password'])) {
  16.       if(($hash = sha1($_POST['password'].'magicsalt'.$_POST['username']))
  17.                 == 'e48695647d8ec2db8447b83e2782a078ace97a5c') {
  18.         $_SESSION['user'] = array('username' => $_POST['username'], 'hash' => $hash);
  19.       }
  20.     }
  21.   }
  22.  
  23.   // log out form
  24.   if($_POST['action'] == 'logout') {
  25.     session_unset();
  26.   }
  27.  
  28.   // add cookie form
  29.   if($_POST['action'] == 'cookie') {
  30.     if(isset($_POST['key']) && isset($_POST['value']) && isset($_POST['age'])) {
  31.       setcookie($_POST['key'], $_POST['value'], time()+$_POST['age'], '/sudoku.php', 'localhost');
  32.       header('Refresh: 0;');
  33.       exit();
  34.     }
  35.  
  36.     print('<br><br>');
  37.     foreach ($_COOKIE as $key => $value) {
  38.       print($key.'<br>');
  39.       print_r('&nbsp;&nbsp;&nbsp;&nbsp;'.$_COOKIE[$key]);
  40.       print('<br><br>');
  41.     }
  42.   }
  43. }
  44.  
  45.  
  46. // display content
  47. if(isset($_SESSION['user'])) {
  48.   print_r($_SESSION['user']);
  49.  
  50.   print('
  51.  <form method="POST">
  52.    <input type="text" name="key" placeholder="Key"><br>
  53.    <input type="text" name="value" placeholder="Value"><br>
  54.    <input type="number" name="age" placeholder="Age"><br>
  55.    <input type="hidden" name="action" value="cookie">
  56.    <input type="submit" value="Create"><br>
  57.  </form>
  58.  ');
  59.  
  60.   foreach($_COOKIE as $key => $value) {
  61.     print($key.'<br>');
  62.     print('&nbsp;&nbsp;&nbsp;&nbsp;'.$value.'<br>');
  63.   }
  64.  
  65.   print('
  66.  <form method="POST" style="position: absolute; right: 0; bottom: 0; margin: 0; padding: 5px;">
  67.    <input type="hidden" name="action" value="logout">
  68.    <input type="submit" value="Log Out">
  69.  </form>
  70.  ');
  71. }else {
  72.   print('
  73.  <form method="POST">
  74.    <input type="text" name="username" placeholder="Username"><br>
  75.    <input type="password" name="password" placeholder="Password"><br>
  76.    <input type="hidden" name="action" value="login">
  77.    <input type="submit" value="Login"><br>
  78.  </form>
  79.  ');
  80. }
  81.  
  82.  
  83. $counter = $_COOKIE['counter'] ?? 0;
  84. $counter += 1;
  85. setcookie('counter', $counter, time()+60*60*24*365);
  86. print('<span style="position: absolute; bottom: 0; left: 0;">&nbsp;user counter: '.$counter.'</span>');
  87. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement