the problem isn't with the login script it's my main page that I want to change depending on if someone is logged in or not but I shall post everything and maybe someone can edit my main page :P
This is what is on my index page that goes to my dynamic page that contains my login information:
Code:
<div id="left">
<?php
require_once "./lmenu2.php";
?>
This is my lmenu2.php. This is what get's displayed on my main page and is where I think my error is. I want it so that if I am logged in it shows members.php and if I'm not logged in it shows the login.php however it only ever shows members.php.
Code:
<?php
function checkLogin($levels)
{
if(!$_SESSION['logged_in'])
{
$access = FALSE;
}
else {
$kt = split(' ', $levels);
$query = mysql_query('SELECT Level_access FROM users WHERE ID = "'.mysql_real_escape_string($_SESSION['user_id']).'"');
$row = mysql_fetch_assoc($query);
$access = FALSE;
while(list($key,$val)=each($kt))
{
if($val==$row['Level_access'])
{//if the user level matches one of the allowed levels
$access = TRUE;
}
}
}
if($access==FALSE)
{
include_once("login/members.php");
}
else {
include_once("login/login.php");
}
if($access==TRUE)
{
include_once("login/login.php");
}
}
checkLogin('1 2');
?>
Here is my login code:
Code:
require_once('db.php');
include('functions.php');
if(isset($_POST['Login']))
{
if($_POST['username']!='' && $_POST['password']!='')
{
//Use the input username and password and check against 'users' table
$query = mysql_query('SELECT ID, Username, Active FROM users WHERE Username = "'.mysql_real_escape_string($_POST['username']).'" AND Password = "'.mysql_real_escape_string(md5($_POST['password'])).'"');
if(mysql_num_rows($query) == 1)
{
$row = mysql_fetch_assoc($query);
if($row['Active'] == 1)
{
session_start();
$_SESSION['user_id'] = $row['ID'];
$_SESSION['logged_in'] = TRUE;
header("Location: http://www.christian-debate.com/barbershop/index.php");
}
else {
$error = 'Your membership was not activated. Please open the email that we sent and click on the activation link';
}
}
else {
$error = 'Login failed !';
}
}
else {
$error = 'Please user both your username and password to access your account';
}
}
And my members.php code: (btw can anyone write up the logout code for this using some type of submit form?
Code:
<?php
session_start();
require_once('db.php');
include('functions.php');
$query = "SELECT * FROM users";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
echo "Welcome <b>" .$row['Username']."</b>. You are now logged in.";
?>
<form action="login/logout.php" >
<input type="submit" value="Logout" action="$logout"/><br/>
</form>