Hi all,
I've been using .htaccess and those little gray login boxes to password-protect the member section of my site for years now. The biggest downside is that, to keep the flow the way I want... I need to practically keep two versions of the site posted, one in the protected "members" directory, and one in the root folder. (That and the fact that I have to keep all my links relative because if folks login to "http:rimea.org" and then clicked a link that read "http://www.rimea.org" it would prompt them to login again... ugh.)
I am most definately a PHP novice... but I'd wanted to play around with using PHP to create sessions and then simply add a tag to the top of each "protected" page to check and see if the user is currently logged in.
Following a tutorial I found online... I can check usernames and password against a table in a MySQL database. Works great. I can now add this header on any particular page to check to see if the user has logged in:
<?php
session_start();
// is the one accessing this page logged in or not?
if (!isset($_SESSION['db_is_logged_in'])
|| $_SESSION['db_is_logged_in'] !== true) {
print "Logged In!";
// not logged in, move to login page
header('Location: login.php');
exit;
}
?>
So far it works fine... but I was wondering if using the same logic if I could display {print} a simple bit of text on each page telling the user if he/she is currently logged in or not. In other words, on every page of the site, whether the page is "member-protected" or not... is there something I can use that would display something like "You are logged in" or "You are not logged in"?
Thanks for reading.
~Wayne