Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question
    
What exactly is not working, getting the session var? –  Teodor Talov Jan 31 at 14:35
    
possible duplicate of Passing JavaScript Variable to PHP Session variable –  Cerbrus Jan 31 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 at 14:38

1 Answer 1

up vote 1 down vote accepted

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');
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.