This line:
session_destroy()
^-- right there
is missing a closing semi-colon
session_destroy();
Which is the cause for the Unexpected End of File error
error message.
Notes:
Using your present code, you may very well get the following error message: (which I tested)
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at...
It's best to use the following method, placing session_start();
above any output:
Sidenote: I am uncertain why you're using session_start();
in your code, since there are no session variables in your posted code. If you're not going to be using something to the effect of $username=$_SESSION['username'];
then you can safely remove it.
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>Remember UserName</title>
<?php
if (isset($_POST['Submit1'])) {
$username = $_POST['username'];
if ($username == $_POST['username']) {
print "Welcome back, ". " $username ";
print "Would you like to log out?";
echo '<form action="Logout" method="post">
<Input Type = "Submit" Name = "Logout" Value = "Logout">
</FORM>';
}
else {
print ("You're not logged in to this site");
}
}
if (isset($_POST['Logout'])) {
$Logout = $_POST['Logout'];
if ($Logout == $_POST['Logout'])
print "You are now logged out";
session_destroy();
}
?>
</head>
<body>
<Form name ="form1" Method ="POST" Action ="index.php">
<Input Type = "text" Value ="username" Name ="username">
<Input Type = "Submit" Name = "Submit1" Value = "Login">
</FORM>
</body>
</html>
Additional notes:
I also noticed a few discrepencies in your logout button.
This echo '<form action="Logout" method="post">
should be replaced with echo '<form action="" method="post">
(unless you're using an actual file, yet this seems to be most unlikely)
Plus, you can narrow this down:
if (isset($_POST['Logout'])) {
$Logout = $_POST['Logout'];
if ($Logout == $_POST['Logout'])
print "You are now logged out";
session_destroy();
}
to:
if (isset($_POST['Logout'])) {
print "You are now logged out";
session_destroy();
}
Complete rewrite:
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>Remember UserName</title>
<?php
if (isset($_POST['Submit1'])) {
$username = $_POST['username'];
if ($username == $_POST['username']) {
print "Welcome back, ". " $username ";
print "Would you like to log out?";
echo '<form action="" method="post">
<Input Type = "Submit" Name = "Logout" Value = "Logout">
</form>';
}
else {
print ("You're not logged in to this site");
}
}
if (isset($_POST['Logout'])) {
print "You are now logged out";
session_destroy();
}
?>
</head>
<body>
<form name ="form1" Method ="POST" Action ="">
<Input Type = "text" Value ="username" Name ="username">
<Input Type = "Submit" Name = "Submit1" Value = "Login">
</form>
</body>
</html>