<?
session_set_cookie_params(60*60*24);
session_start();
# The above should be the first and in the given order.

?>
<html><body><center>


<form name="form1" action="" method="post">
Enter username: <input name="user" type="text" size="10">
<input type="hidden" name="submitted" value="true">
<input type="submit" value="SUBMIT">
</form>

<?
if (isset($_REQUEST['submitted']))
{
	$username = $_REQUEST['user'];
	// If the user is not in the session (e.g. first visit), add him
	if (!isset($_SESSION['user']))
        	$_SESSION['user'] = "$username";

	else
	{
		// If the user is already in the session, retrieve him
        	$username = $_SESSION['user'];
        	echo "Your username is: $username<br>";
	}

	// If the counter has no value yet (e.g. first visit), initialize it
	if (!isset($_SESSION))
        	$_SESSION['counter'] = 0;
	else
	{
		// Otherwise, get the value of the counter
		$_SESSION['counter']++;
        	$count = $_SESSION['counter'];
        	echo "This computer visited the homepage: $count times.";
	}

	 echo "<br><a href='session2_clean.php'>Members Area</a>";
        /* If cookies are disabled, you need to replace the above line by the one below*/
        //echo "<br><a href='session2.php?", strip_tags(session_id()), "'>Members Area</a>";
}
?>

</center></body></html>
