weixin_33725272 2015-11-22 20:42 采纳率: 0%
浏览 52

用$ .ajax更改$ _SESSION

The actual page launch an $.ajax (POST) request and the receiver.php need to modify the $_SESSION. However it do not work, i don't know whether the id of $_SESSION is different or if i need a refresh on the page for register the modification.

I tried to transfer the session id and modifiy it with :

<?php
    if ( count( $_POST ) > 1 && isset( $_POST["s"] ) )
    {
        session_id( $_POST["s"] );
        session_start();
    }
?>

but this code is ineffective...

My $.ajax request is simple :

var s = <?php echo "'" . session_id() . "'"; ?>;

$.ajax({
    url: 'jquery/receiver.php',
    type: 'POST',
    dataType: 'html',
    data: {
        s: s, // session id, useless?
        // data...
    },
}).done(function ( data ) {
    // operations ...
}

My receiver.php too ;

<?php
    if ( count( $_POST ) > 1 && isset( $_POST["s"] ) )
    {
        session_id( $_POST["s"] );
        session_start();
    }

    $_SESSION['longarray']['key'] = 'value';
?>

Finally, it is possible to modify $_SESSION with $.ajax (POST) ? Or maybe i have only a problem because my $_SESSION is a array ?

  • 写回答

2条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 c++字符串分割问题
      • ¥15 关于#sql#的问题:没有用命令关闭cdc,手动把系统表开启的cdc右键删除了
      • ¥15 android freedom
      • ¥15 使用自定义的类型代替内置类型可行吗
      • ¥15 关于STM32的SPI和ENDAT接口编码器通信的问题
      • ¥15 关于#pdfbox#生成的PDF文件正常,转图片中文乱码的问题,如何解决?
      • ¥15 ADS中有关DAC控件的使用问题
      • ¥15 win11如何运行geoserver
      • ¥15 审稿意见请教-用ERNIE进行小样本分类的对比实验问题
      • ¥15 gem5搭建arm v8