hello
I am new to php and know a little HTML & CSS
I have copied some code from a tutorial just to test a home server I have setup. the code was working and some of it still does but a part of it doesnt work and leaves me with a blank screen.
the part that doesnt seem to work is the else part of the statement.
the code is for a very basic login page.
here is the HTML for my index page
<!DOCTYPE html>
<head>
<title>Login Page</title>
</head>
<body>
<!-- Output error message if any -->
<?php echo $error; ?>
<!-- form for login -->
<form method="post" action="/php/login.php">
<label for="username">Username:</label><br/>
<input type="text" name="username" id="username"><br/>
<label for="password">Password:</label><br/>
<input type="password" name="password" id="password"><br/>
<input type="submit" value="Log In!">
</form>
</body>
</html>
and the code for my php login page
<?php
// Start the session
session_start();
// Defines username and password. Retrieve however you like,
$username = "user";
$password = "password";
// Error message
$error = "";
// Checks to see if the user is already logged in. If so, refirect to correct page.
if (isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] == true) {
$error = "success";
header('Location: success.php');
}
// Checks to see if the username and password have been entered.
// If so and are equal to the username and password defined above, log them in.
if (isset($_POST['username']) && isset($_POST['password'])) {
if ($_POST['username'] == $username && $_POST['password'] == $password) {
$_SESSION['loggedIn'] = true;
header('Location: success.php');
} else {
$_SESSION['loggedIn'] = false;
$error = "Invalid username and password!";
}
}
?>
the login page works when I type the correct user name and password and takes me to the success page/php file
which is
<?php
// Start the session
ob_start();
session_start();
// Check to see if actually logged in. If not, redirect to login page
if (!isset($_SESSION['loggedIn']) || $_SESSION['loggedIn'] == false) {
header("Location: index.html");
}
?>
<h1>Logged In!</h1>
<form method="post" action="logout.php">
<input type="submit" value="Logout">
</form>
but if i enter and incorrect username/password it redirects me to the login.php file but its blank.
it did work at first but now nothing.
as i said i am very new to php so any help would be very much appreciated
thanks
matthew