weixin_33722405 2017-09-02 12:21 采纳率: 0%
浏览 27

AJAX会话PHP错误

I have been performing session creation using PHP. I'm trying to create session using AJAX call.

This is my ajax call code :

var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://www.vedarjana.com/signin.php');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function() {
    console.log('Signed in as: ' + xhr.responseText);
};
xhr.send('id=' + "123");
xhr.onreadystatechange = function() {
    if (xhr.readyState == XMLHttpRequest.DONE) {
        if (xhr.responseText == '') {
            //alert(xhr.responseText);

        } else {

            location.reload();
        }
    }
}

Now This is my PHP code for session generation :

session_start();
$_SESSION["frontUserIslogin"] = true;
$_SESSION["frontUserId"] = "123";
$_SESSION["frontUserName"] = "abc";
$_SESSION["frontUserProfilePic"] = "abc.png";
echo $_SESSION["frontUserName"];

Now when I perform AJAX call, session is generating as its returning username. But when page reloads, I'm checking var_dump($_SESSION) then its showing NULL

Please help me I'm stuck on it from last 3 weeks

Thanks in advance

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 家用射频美容仪技术规格
    • ¥25 matlab数值溢出该怎么解决?
    • ¥15 大家帮我看看为什么错了
    • ¥15 unity互动琴弦抖动效果
    • ¥15 做了个的二极管反向饱和电流测量电路,但是测试达不到效果
    • ¥15 nginx无证书访问https失败
    • ¥15 树莓派启动AP热点传入数据
    • ¥15 multisim中关于74ls192n和DSWPK开关的问题(相关搜索:计数器)
    • ¥15 在误装Windows server2019 后如何利用Windows.old恢复?
    • ¥20 代码实现状态连接包过滤防火墙的设计与实现