Ok, check it. Session variables in PHP are actually pretty easy. The method I typically use is to have one page that initializes everything. This page is called on every other page. It would look something like this:
CODE
<?php
// preProcess.php
// Connect to database.
// etc... etc...
session_name("mySiteName");
session_start();
?>
Then, as an example, lets take your login page. It would look something like this.
CODE
if (isset($_SESSION["first_name"]))
{
header("Location: index.php");
exit;
}
$login_query = mysql_query("SELECT passwd FROM sqdbs_peoples WHERE first_name = '$_POST['first_name']' AND second_name = '$_POST['second_name']' AND last_name = '$_POST['last_name']' AND dnum = '$_POST['dnum']'");
$passhash = mysql_result($login_query,"1","passwd");
if (isset($passhash))
{
if (md5($_POST['passwd']) == $passhash)
{
start_session();
$_SESSION['first_name'] = $_POST['first_name'];
$_SESSION['second_name'] = $_POST['second_name'];
$_SESSION['last_name'] = $_POST['last_name'];
$_SESSION['dnum'] = $_POST['dnum'];
$index_query = mysql_query("SELECT index FROM sqdbs_peoples WHERE first_name = '$_SESSION['first_name']' AND second_name = '$_SESSION['second_name']' AND last_name = '$_SESSION['last_name']' AND dnum = '$_SESSION[dnum]' ")
$_SESSION['first_name'] = $_POST['first_name'];
$_SESSION['first_name'] = $_POST['first_name'];
$_SESSION['first_name'] = $_POST['first_name'];
session_write_close();
header("Location: index.php");
exit;
}
}
On every page I include the "preProcess.php" file to start the session. If the page requires the user to be logged in, you check for a session variable to be set. If it isn't, redirect to the login page. Please note that I am using "header" to redirect. If you've already sent out page content, headers will already be sent, an error will occur, and the redirect will not happen. To remedy this you can turn on "output buffering". Also be aware, however, that you'll need to force your session to write to disk before redirecting by using "session_write_close()".