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.
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.