login.html

 

代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript">
var xmlHttp = false;
function createXMLHttpRequest()
{
    
var http;
    
if(window.ActiveXObject)
    {
        http 
= new ActiveXObject('Microsoft.XMLHTTP');
    }
    
else if(window.XMLHttpRequest)
    {
        http 
= new XMLHttpRequest();
    }
    
return http;
}
function setSessionLifetime(checked) {
    xmlHttp 
= createXMLHttpRequest();
    
var url = 'session_setup.php';
    
if (checked == true) {
        url 
+= '?set=1';
    } 
else {
        url 
+= '?set=0';
    }
    xmlHttp.open(
"GET", url, true);
    xmlHttp.onreadystatechange 
= function() {
        
if(xmlHttp.readyState==4 && xmlHttp.status==200)
        {
            window.location.href
='session_printlifetime.php';
        }
    }
    xmlHttp.send(
null);
}
</script>
</head>

<body>
<?php ?>
<input type="checkbox" name="setlifetime" id="setlifetime" value="1" onclick="setSessionLifetime(this.checked)" />set one life's session lifetime
</body>
</html>

session_setup.php

代码
<?php
session_start();
$set = isset($_GET['set']) ? $_GET['set': 0;
$lifetime = ($set == 1? (60 * 60 * 24 * 365: ini_get('session.gc_maxlifetime');
$_SESSION['USER'= 'ADMIN';
setcookie(session_name(), session_id(), time() + $lifetime, "/");
?>

session_printlifetime.php

代码
<?php
session_start();
if (isset($_SESSION['USER']) && $_SESSION['USER'!= '') {
    
echo $_SESSION['USER'];
    
echo '<input type="button" value="refresh" onclick="window.location.href=\'session_printlifetime.php\'"/>';
else {
    
echo 'session die';
}
?>