<?php
session_name("sessiontest");
session_start();
$private_id = session_id();
$ntest = $_SESSION["test"];
$stest_one = $_SESSION["test_one"];
$stest_two = $_SESSION["test_two"];
$stest_three = $_SESSION["test_three"];
session_write_close();
$ntest = 0;
$stest_one = "Top";
$stest_two = "Upper";
$stest_three = "Lower";
?>
<!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>Session test</title>
<style>
div {
text-align: center;
}
span {
cursor: pointer;
color: #0000bb;
}
span:hover {
text-decoration: underline;
font-weight: bold;
}
</style>
<script>
var nnum = 0;
function fsessiontest(ospan) {
nnum++;
var stime = ospan.id.substr(0, ospan.id.length-4);
if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest();
} else {
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("POST", "sessiontest.php", false);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
ospan.innerHTML = xhttp.responseText;
}
}
xhttp.send("nnum=" + nnum + "&stime=" + stime);
}
function fdestroysession() {
if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest();
} else {
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("POST", "destroysessiontest.php", false);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
document.getElementById("destroysessionspan").innerHTML = xhttp.responseText;
}
}
xhttp.send("");
}
</script>
</head>
<body>
<div id="firstdiv"> <span id="firstspan" onClick="javascript:fsessiontest(document.getElementById('firstspan'));"> <?php echo $stest_one; ?> </span> <br /> </div>
<div id="seconddiv"> <span id="secondspan" onClick="javascript:fsessiontest(document.getElementById('secondspan'));"> <?php echo $stest_two; ?> </span> <br /> </div>
<div id="thirddiv"> <span id="thirdspan" onClick="javascript:fsessiontest(document.getElementById('thirdspan'));"> <?php echo $stest_three; ?> </span> <br /> </div>
<div> <span id="destroysessionspan" onClick="javascript:fdestroysession();"> Bottom (end session) </span> </div>
</body>
</html>
<?php
session_name("sessiontest");
session_id($private_id);
session_start();
$_SESSION["test"] = $ntest;
$_SESSION["test_one"] = $stest_one;
$_SESSION["test_two"] = $stest_two;
$_SESSION["test_three"] = $stest_three;
session_write_close();
?>