Iv'e done this many time before.. this is how..
I made a header file (header.inc) and in that file was the top half of my HTML page.. (nav links..ad banners etc etc). Also in that file was some PHP.. before u put your HTML in.. you want to make sure that..
<?php
session_start();
?>
then put the top half of ur HTML in. Whe you reach the end of the header file put this in..
<?php
if(!session_is_registered("ID") && $secure) {
// print out login form informing the user that this is a private page..
exit;
}
?>
the exit bit is important as it kills the script execution there and then. In other words, unless the user has access by supplying a username and password.. the members pages won't get printed. When the user logs in.. it is a good idea to get that user's ID from the DB and store it in a session.. that way.. you can do things like.. "welcome, $username." when they login. In other words you know who's logged in. Using this method.. you could wrote a log file or something (but that's going off the topic a bit). But in the code above.. I used session_is_registered("ID").. when I registered my sessions.. I had..
// data pulled out from db and stored in an array $r
$ID = $r[ID];
session_register("ID");
Now at the top of ALL your member pages.. put
$secure = 1;
This will lock the member pages and force the code in header.inc to run proventing unauthorized access to members pages.
now every page you make for the whole site would look something like..
<?php
include("header.inc"); // contains session_start() and other code
?>
HTML body can go here.. content of whatever page (e.g welcome.php) your making.
<?php
include("footer.inc"); // this would close all the HTML tags left open by header.inc
?>
Here a little example of what would happen if a user attempted to access a member page..
header.inc will be loaded.. the php will do a start_session().. then all the opening HTML tags would be put in place.. then php will check to see if there's a session registered and if the page being requested is locked.. if a session id registered and the page is locked, then the member page would be displayed.. if a session was registered and the page requested was unlocked.. the member page would be displayed.. if no session was registered and the page requested was locked then.. prompt for a user and pass..
This, I believe would be a complete solution to your problem 😉
Good Luck..
Regards, Stezz.