[英]Create PHP session variable inside Kinetic.js/Javascript
I am trying to create a PHP session variable inside of Kinetic.js/Javascript. 我正在尝试在Kinetic.js / Javascript中创建一个PHP会话变量。
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'. 单击形状后,我希望会话变量存储字符串的'key'属性,然后转到'create.php'。
How can I do this? 我怎样才能做到这一点?
EDIT: Cerbrus, I tried you suggestion: 编辑:Cerbrus,我尝试过您的建议:
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': 用户被发送到'create.php',但是当我尝试在'create.php'中打印它时:
<?php
echo $_GET['roomName'];
?>
Nothing is echoed 没有回音
You have to set roomName parameter in url so it can be read by your php script. 您必须在url中设置roomName参数,以便您的php脚本可以读取它。
window.location.href = 'create.php?roomName='+ encodeURIComponent('hello');
You can do the same to send the id. 您可以执行相同的操作来发送ID。
window.location.href = 'create.php?roomName='+shape.getAttr('key');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.