For # 1 use session_set_cookie_params(). Expires after 600 seconds
session_set_cookie_params(600)
(note, unlike a regular setcookiefunction, it session_set_cookie_paramsuses the seconds in which you want it to live, it should not be time() + 600, which is a common mistake)
For number 2, just create a small script called via AJAX:
<?php
session_start()
if( empty($_SESSION['active']) ) {
print "Expired"
}
else {
print "Active"
}
?>
Javascript ( JQuery)
$.get('path/to/session_check.php', function(data) {
if( data == "Expired" ) {
alert("Session expired");
} else if (data == "Active" ) {
alert("Session active");
}
});