Advertisement
Guest User

Untitled

a guest
Jan 28th, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?PHP
  2.  
  3. session_start();
  4. if(!isset($_SESSION['value'])) {
  5. $_SESSION['value'] = 0;
  6. }
  7.  
  8. if(isset($_GET['action'])) {
  9. switch($_GET['action']) {
  10. case 'add':
  11. $_SESSION['value'] ++;
  12. break;
  13. case 'remove':
  14. $_SESSION['value'] --;
  15. break;
  16. case 'reset':
  17. $_SESSION['value']= 0;
  18. break;
  19. }
  20.  
  21. header("Location: index.php");
  22. exit();
  23. }
  24. ?>
  25.  
  26. <html>
  27. <head>
  28. <title>Storing user values in session</title>
  29. </head>
  30. <body>
  31. <p>The current value is: <?PHP echo $_SESSION['value']; ?></p>
  32.  
  33. <script>
  34. document.onkeyup = checkKey;
  35.  
  36. function checkKey(e) {
  37. var location = '/index.php';
  38. e = e || window.event;
  39.  
  40. if (e.keyCode == '13') {
  41. window.location = location + '?action=reset';
  42. // up arrow
  43. }
  44. else if (e.keyCode == '38') {
  45. window.location = location + '?action=add';
  46. // up arrow
  47. }
  48. else if (e.keyCode == '40') {
  49. window.location = location + '?action=remove';
  50. // down arrow
  51. }
  52. else if (e.keyCode == '37') {
  53. // left arrow
  54. }
  55. else if (e.keyCode == '39') {
  56. // right arrow
  57. }
  58.  
  59. }
  60. </script>
  61. </body>
  62. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement