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

# The line below checks if cookie is set.
//echo "isset(\$_COOKIE['PHPSESSID']): ", isset($_COOKIE["PHPSESSID"]), "<p>";

# The line below checks if the session ID is transmitted by GET method
//echo "Using \$_GET['PHPSESSID']: ", $_GET['PHPSESSID'], "<br>";

# Here is how to access the session ID number using SID constant
// echo "The session ID number (SID) using SID is: ", SID, "<br>";

# Here is how to access the session ID number using session_id()
// echo "The session ID number using session_id() is: ", session_id(), "<br>";

# Here is how to access the session name which is the name of the 
# cookie storing the session ID. If you provide an argument to 
# the function, the name of the session will change
//echo "The session name is: ", session_name(), "<br>";

# Here is how to access the path where the session flat file is saved.
# The default is the tmp directory on the server. If you provide an 
# argument to it (in that case, you must use it before session_start() and 
# it should be in every page in the session), the path will change to the one 
# you provide.
// echo "The session is saved in: ", session_save_path(), "<br>";

# Here is how to get the parameters of the session cookie
/* $array = session_get_cookie_params();
echo "Contents of the session cookie: <br>";
foreach ($array as $v)
        echo "$v<br>";
*/

//print_r($array);
?>
<html>
<body>
<center>

<?


if (!isset($_SESSION['user']))
        $_SESSION['user'] = "abu-jeib";

else
{
        $username = $_SESSION['user'];
        echo "Your username is: $username<br>";
}

if (!isset($_SESSION))
        $_SESSION['counter'] = 0;
else
{
	$_SESSION['counter']++;
        $count = $_SESSION['counter'];
        echo "This computer visited the homepage: $count times.";
}

//echo "<br><a href=\"session2.php?",strip_tags(SID),"\">Session 2</a>";
?>
<!--
You need to append the session ID to the URL if you want to pass 
the ID through URLs not through session cookie.# Here is how to access the session ID number using session_id()
-->
<!--<br><a href="session2.php?<?echo strip_tags(SID); ?>">Session 2</a>-->
<br><a href="session2.php?<?echo strip_tags(session_id()); ?>">Session 2</a>
<!--<br><a href="session3.php?<?echo strip_tags(session_id()); ?>">log out</a>-->
</center></body></html>
