Traq, I may owe you a pretty big apology. I was trying *not* to post code that wasn't strictly relevant, so as not to clutter things up. The risk is, of course, that one leaves something essential out. I might have done that, entirely inadvertently. I'm sorry if that turns out to be true.
I've posted the 'log_in' page and the 'add_entry' page. I thought that would be enough. There is another page which would go, chronologically speaking, in between those two: the 'logged_in' page.
I'll post the code below. The reason that there are three pages is because the book I was relying on used three pages and I wasn't sure how to combine any of them.
*Important* - the code below supposedly redirects any user who is not logged in back to the log_in page. That has never happened to me.
Code:
<?php # Script 11.5 (DWS) - loggedin.php
// Refers to: first_name; login.php.
ob_start(); // Start output buffering.
require_once ('./includes/config.inc.php');
// Include the configuration file for error management and such.
$page_title = 'Logged in';
include ('./includes/header.html');
// Set the page title and include the HTML header.
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Logged In!</title>
</head>
<body>
<?php
// Greet the user by name.
if (isset($_SESSION['first_name']) ) {
echo "You are now logged in, {$_SESSION['first_name']}. <br><br><br>
If you would like to post a new entry, go to the <a href='add_entry.php'>New entry</a> page.</p>";
} else {
// If no session value is present, redirect the user.
ob_end_clean(); // Delete the buffer.
// Start defining the URL.
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
// Check for a trailing slash.
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
$url = substr ($url, 0, -1); // Chop off the slash.
}
$url .= '/login.php'; // Add the page.
header("Location: $url");
exit(); // Quit the script.
}
echo '</body>
</html>';
ob_end_flush();
// Send everything to the Web browser.
?>
Bookmarks