A tumblelog CMS built on AJAX, PHP and MySQL.

form.autosave.php 819B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. session_start();
  3. function isAjax() {
  4. return isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
  5. $_SERVER ['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
  6. }
  7. function saveForm() {
  8. $type = getMethod();
  9. $id = ($type=='GET') ? $_GET['autosaveid'] : $_POST['autosaveid'];
  10. $_SESSION[$id] = $_SERVER['QUERY_STRING'];
  11. echo date('H:i | d/m/y',time());
  12. }
  13. function loadForm() {
  14. $type = getMethod();
  15. $id = ($type=='GET') ? $_GET['autosaveid'] : $_POST['autosaveid'];
  16. if(isset($_SESSION[$id]))
  17. echo $_SESSION[$id];
  18. }
  19. function isLoad() {
  20. $type = getMethod();
  21. if($type=='GET' and isset($_GET['autosave'])) return true;
  22. elseif(isset($_POST['autosave'])) return true;
  23. return false;
  24. }
  25. function getMethod() {
  26. return $_SERVER['REQUEST_METHOD'];
  27. }
  28. if(isAjax()) {
  29. if(isLoad()) loadForm();
  30. else saveForm();
  31. }
  32. exit;
  33. ?>