duanmu6231 2013-11-21 10:34
浏览 50

在每个ajax调用中重新创建php会话

I'm trying to write a mobile web app with JqueryMobile, the mobile will be my client, I also have a php service that will manage login sessions, but the php creates a new session in each ajax calls, I see the generated session files in my session file path, I need to resume the php sessions.

The php file is look like this :

header("Content-type: text/html; charset=utf-8");
header("Access-Control-Allow-Origin: *");

require 'connect_to_db.php';

// Starting the session
session_name('MySessionName');

// Making the cookie live for 2 weeks
session_set_cookie_params(2*7*24*60*60);

session_start();
...
// checking if loged in ...
?>

and the ajax request :

$.ajax({
    url: baseUrl + "login.php",
    crossDomain: true,
    type: "POST",
    data:{
        command: "Login",
        username: $("#username").val(),
        password: $("#password").val()
    },
    dataType: "json",
    success: function(response)
    {
        $.mobile.changePage("#DataList");
    },
});

I checked many pages from stackoverflow but no success. I'm testing my app in firefox and xampp.

  • 写回答

1条回答 默认 最新

  • dua55014 2013-11-21 10:52
    关注

    Check the request/response headers of the request with the developer tools of your browser. The response headers should contain something like:

    Set-Cookie: MySessionName=abcdef12345; expires=Wed, 21-May-2014 10:46:20 GMT; path=/; HttpOnly
    

    After the first request, the next request need to send the cookie back.

    Cookie: MySessionName=abcdef12345
    

    It is possible that the browser does not accept the cookie (lifetime, 3party, p3p policy, ...). If that's the case and it does not send the session id back, PHP can not identify it and will create a new one.

    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大