0

I am trying to create a PHP session variable inside of Kinetic.js/Javascript.

stage.on('mousedown', function(evt) {
  var shape = evt.targetNode;
  if (shape) {
    if (shape.getFill() == 'green') { 
      //$_SESSION['room_name'] = shape.getAttr('key');
      window.location.href = 'create.php';
    }       
  }
});

When my shape is clicked, I want the session variable to store the 'key' attribute, which is a string, then go to 'create.php'.

How can I do this?

EDIT: Cerbrus, I tried you suggestion:

stage.on('mousedown', function(evt) {
  var shape = evt.targetNode;
  if (shape) {
    if (shape.getFill() == 'green') { 
      var img = new Image();
      img.src = "script.php?roomName=" + encodeURIComponent('hello');
      window.location.href = 'create.php';
    }       
  }
});

The user is sent to 'create.php', but when i tried to print it in 'create.php':

<?php
  echo $_GET['roomName'];
?> 

Nothing is echoed

user2397282
  • 3,798
  • 15
  • 48
  • 94
  • What exactly is not working, getting the session var? – Teodor Talov Jan 31 '14 at 14:35
  • possible duplicate of [Passing JavaScript Variable to PHP Session variable](http://stackoverflow.com/questions/4743842/passing-javascript-variable-to-php-session-variable) – Cerbrus Jan 31 '14 at 14:35
  • The commented out line does not work; Without that line, the user is sent to 'create.php', but when it's in, nothing happens. – user2397282 Jan 31 '14 at 14:38

1 Answers1

1

You have to set roomName parameter in url so it can be read by your php script.

window.location.href = 'create.php?roomName='+ encodeURIComponent('hello');

You can do the same to send the id.

window.location.href = 'create.php?roomName='+shape.getAttr('key');
TSE
  • 356
  • 1
  • 8