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

?>
<html><body><center>

<?
$valid = false;
if (isset($_REQUEST['submitted']))
{
	$username = $_REQUEST['user'];
	$password = $_REQUEST['password'];
	// This should be checked in the database instead
	if ($username == "iyad" && $password == "207")
		$valid = true;
	if ($valid)
	{
		// 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 "Welcome $username<br>";
		}

		echo "<br><a href='with_sessions_see_images.php'>See Images</a>";
		echo "<br><a href='with_sessions_upload_images.php'>Upload Images</a>";
		echo "<br><a href='with_sessions_logout.php'>Log Out</a>";
	}
	else
		echo "Invalid username or password.<br>\n";
}
else // Display the form
{
echo <<< HERE
        <form name="form1" action="" method="post">
        Enter username: <input name="user" type="text" size="10">
        Enter password: <input name="password" type="password" size="10">
        <input type="hidden" name="submitted" value="true">
        <input type="submit" value="SUBMIT">
        </form>
HERE;
}

?>

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