Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- session_start();
- if(!isset($_SESSION['value'])) {
- $_SESSION['value'] = 0;
- }
- if(isset($_GET['action'])) {
- switch($_GET['action']) {
- case 'add':
- $_SESSION['value'] ++;
- break;
- case 'remove':
- $_SESSION['value'] --;
- break;
- case 'reset':
- $_SESSION['value']= 0;
- break;
- }
- header("Location: index.php");
- exit();
- }
- ?>
- <html>
- <head>
- <title>Storing user values in session</title>
- </head>
- <body>
- <p>The current value is: <?PHP echo $_SESSION['value']; ?></p>
- <script>
- document.onkeyup = checkKey;
- function checkKey(e) {
- var location = '/index.php';
- e = e || window.event;
- if (e.keyCode == '13') {
- window.location = 'reset';
- // up arrow
- }
- else if (e.keyCode == '38') {
- window.location = 'add';
- // up arrow
- }
- else if (e.keyCode == '40') {
- window.location = 'remove';
- // down arrow
- }
- else if (e.keyCode == '37') {
- // left arrow
- }
- else if (e.keyCode == '39') {
- // right arrow
- }
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement