After a successful login attempt my php script starts a session like this:
session_set_cookie_params(1800,'/','www.mydomain.com',true);
session_start();
header("location:mainpage.html");
Now my questions are:
- How can I save my user-id to my session for further use?
- Would it be sufficient to add these 3 code snippet to keep my sessions alive in a jQuery Mobile page:
mysession.php:
<?php
session_set_cookie_params(1800,'/','www.mydomain.com',true);
session_start();
?>
somewhere in mainpage.html:
function getHttpRequestObj()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
else
{// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
function callSession(id)
{
var xmlhttp = getHttpRequestObj();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById(id).innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","mysession.php",true);
xmlhttp.send();
}
And then in the outmost div (name='main') in mainpage.html
$(document).ready(function() {
callSession('main');
});