Hi all,
I'm currently playing around with sessions and the following script:
<?php
$s= $_GET['s'];
$end = $_GET['end'];
if($end == 'true'){
// Only attempt to end the session if there
// is a $PHPSESSID set by the request.
if(isset($s)) {
$message = "<p>End of session ($s).";
session_start( );
session_destroy( );
} else {
$message = "<p>There was no session to destroy!";
}
?>
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd" >
<html>
<head><title>Sessions</title></head>
<body>
<?=$message?>
</body>
</html>
<?php
} else {
// Initialize a session. This call either creates
// a new session or re-establishes an existing one.
session_start( );
// If this is a new session, then the variable
// $count will not be registered
if (!session_is_registered("count"))
{
session_register("count");
session_register("start");
$count = 0;
$start = time( );
}
else
{
$count++;
}
$sessionId = session_id( );
?>
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd" >
<html>
<head><title>Sessions</title></head>
<body>
<p>This page points at a session
(<? echo $sessionId?>)
<br>count = <? echo $count?>.
<br>start = <? echo $start?>.
<p>This session has lasted
<?php
$duration = time( ) - $start;
echo "$duration";
?>
seconds.<br>
<br>
<a href="session_test.php?end=true">End session</a>
</body>
</html>
<?
}
?>
I am able end a session by clicking the button but am unable to add a $count to the page. How would i do this with a link (similar to the "End session" link at the bottom of the page) or even by refreshing the page?
Cheers,
chrima