// get the POSTed variables from FORM $username = $HTTP_POST_VARS['username']; $password = $HTTP_POST_VARS['password']; $newlogin = $HTTP_POST_VARS['newlogin']; session_start(); if(isset($HTTP_SESSION_VARS['username']) && isset($HTTP_SESSION_VARS['id'])){ // Successfull login/index.php called again as main page $title = "Welcome to main menu"; include('header.inc.php'); include('menu.inc.php'); if ($debug) include('debug.inc.php'); include('footer.inc.php'); } else { if(($username) && ($password)){ // if POSTed variables are other than NULL $crypted_passwds = "1"; // CRYPTED PASSWORDS ON - TURN OFF BY PUTTING ="" (NULL) if ($crypted_passwds) $password = md5($password); include('./db_simple.inc.php'); $result = mysql_query("SELECT * FROM $maintable WHERE user_name='$username' AND password='$password' AND active='1'") or die (mysql_error()); $num_rows = mysql_num_rows($result); // check if the user info validates the db if($num_rows > 0){ // if login successfull first time - get session values and show last visit $row = mysql_fetch_array($result); // if a session does not yet exist for this user, start one session_start(); // Next, register main variables session_register("id", "username", "user_level", "all_levels"); $HTTP_SESSION_VARS['id'] = $row['id']; $id = $row['id']; $HTTP_SESSION_VARS['username'] = $username; include('user_groups.inc.php'); $title = "Authorization successful - welcome to main menu"; include('header.inc.php'); $result = mysql_query("SELECT last_login FROM $maintable WHERE id = '$id'") or die (mysql_error()); $row = mysql_fetch_array($result); echo "
Welcome - your last visit was " . $row['last_login'] . "
"; $nowlogin = date("r"); $result = mysql_query("UPDATE $maintable SET last_login = '$nowlogin' WHERE id = '$id'") or die (mysql_error()); $ip_address = $HTTP_SERVER_VARS['REMOTE_ADDR']; $result = mysql_query("INSERT INTO $logtable (`id`, `logged_in`, `ip_address`) VALUES ('$id', '$nowlogin', '$ip_address')") or die (mysql_error()); include('menu.inc.php'); include('footer.inc.php'); if ($debug) include('debug.inc.php'); } else { // Faulty access rights - try again $title = "Authorization failed"; include('header_login.inc.php'); ?>