NoPaste

Stempeluhr

von uname

SNIPPET_TEXT:
  1. <!DOCTYPE html>
  2. <html lang="de">
  3.    <head>
  4.       <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5.       <script>
  6.          document.querySelectorAll('button').forEach(function(button) {
  7.            button.addEventListener('click', function(e) {
  8.              e.preventDefault();
  9.              var xhr = new XMLHttpRequest();
  10.              xhr.open('POST', 'index.php');
  11.              xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  12.              xhr.onreadystatechange = function() {
  13.                if (xhr.readyState === 4 && xhr.status === 200) {
  14.                  location.reload();
  15.                }
  16.              };
  17.              xhr.send(document.getElementById('klick').serialize() + '&submit=' + button.getAttribute("value"));
  18.            });
  19.          });
  20.       </script>
  21.    </head>
  22.    <body>
  23.       <form action="" method="post" id="klick">
  24.          <button type="submit" name="send_form" value="kommt">kommt</button>
  25.          <button type="submit" name="send_form" value="geht">geht</button>
  26.       </form>
  27.       <?php
  28.          if (isset($_POST['send_form']))
  29.          {
  30.            $update = $_POST['send_form'];
  31.          }
  32.          $filename="time.txt";
  33.          $fp = @fopen($filename, "r");
  34.          if ($fp)
  35.          {
  36.            $content = file_get_contents ($filename);
  37.            fclose($fp);
  38.          }
  39.          if ($update)
  40.          {
  41.            $timestamp = time();
  42.            $time = date("Ymd;Hi",$timestamp);
  43.            $day = date("Ymd",$timestamp);
  44.            $t = $time . ";" . $update;
  45.            $backupfile = 'backup/'.$day.'.txt';
  46.          
  47.            $fp = @fopen($filename, "w");
  48.            if ($fp)
  49.            {
  50.              fwrite($fp, $t);
  51.              fwrite($fp, "\n");
  52.              fwrite($fp, $content);
  53.              fclose($fp);
  54.            }
  55.            $fp = @fopen($backupfile, "w");
  56.            if ($fp)
  57.            {
  58.              fwrite($fp, $t);
  59.              fwrite($fp, "\n");
  60.              fwrite($fp, $content);
  61.              fclose($fp);
  62.            }
  63.          }
  64.          $file = file($filename);
  65.          foreach ($file as $line)
  66.          {
  67.            echo $line;
  68.            echo "<br>";
  69.          }
  70.          ?>
  71.    </body>
  72. </html>

Quellcode

Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. PASTEBIN_DOWNLOAD_SNIPPET_EXPLAIN