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

3
  • What exactly is not working, getting the session var? Commented Jan 31, 2014 at 14:35
  • possible duplicate of Passing JavaScript Variable to PHP Session variable Commented Jan 31, 2014 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. Commented Jan 31, 2014 at 14:38

1 Answer 1

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');
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.