admin管理员组文章数量:1435859
function changeClient(s) {
if(s.value!=0)
{
document.location.href = "map.php?c="+s.value;
}
I have to assign the value of s to a session variable $_SESSION['id'].How can i?
function changeClient(s) {
if(s.value!=0)
{
document.location.href = "map.php?c="+s.value;
}
I have to assign the value of s to a session variable $_SESSION['id'].How can i?
Share Improve this question edited Jun 17, 2011 at 7:16 JiminP 2,1321 gold badge20 silver badges26 bronze badges asked Jun 17, 2011 at 7:13 AshithaAshitha 814 silver badges12 bronze badges4 Answers
Reset to default 2You can not assign client side variable(Javascript) to server side variable(PHP).
You have to use ajax to do this.
<script>
function assignJsValueToPHPSession()
{
var jsVar = 1;
$.ajax({
type:post,
url: "test.html",
data: 'sessionjsvar=' + jsVar,
success: function(){
$(this).addClass("done");
}
});
}
test.php
<?php
$_SESSION['phpvalue'] = $_POST['sessionjsvar'];
?>
You can set cookie using javascript and the same cookie will be accessible in server side variable(PHP).
$.cookie("name1", "test"); // emample 1
$.cookie("name1", "test", { expires: 7 }); // emample 2
$.cookie("name1", "test", { path: '/User', expires: 7 }); // emample 3
Get a cookie
alert( $.cookie("test") );
//In PHP
<?php
print_r($_COOKIE);
print)r($_REQUEST);
?>
$_SESSION['id'] = $_GET['c']
set the GET parameter you sent to a session variable.
$_SESSION['id'] = $_GET['c']
Just check c
is really in the URL first.
本文标签: phpHow can I assign a javascript variable to the session valueStack Overflow
版权声明:本文标题:php - How can I assign a javascript variable to the session value - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745675242a2669811.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论