I am fairly new at programming and I am running into a problem. What I am trying to do is have my login.php create and declare the session variables, then my dashboard.html file should only show the current html if $_SESSION['isloggedin'] is set. I tested to make sure login.php was declaring the session variable and it is. Im not sure what I am doing wrong, any help is greatly appreciated. I left out a lot of the dashboard html in the middle because it is quite extensive. Thanks!
Login.php
?php
session_start();
include 'dbconnect.php';
$username = $_POST['username'];
$password = $_POST['password'];
function login($email, $password) {
$login = mysql_query("SELECT * FROM (Teachers) where email = '$email' and password = '$password'");
if (mysql_fetch_row($login)>0){
if(!$login){
die('Could not securely login to your account. Error e09993');
}
else{
$_SESSION['name']= mysql_fetch_row($login)[2];
$_SESSION['email']= mysql_fetch_row($login)[1];
$_SESSION['lastName']= mysql_fetch_row($login)[3];
$_SESSION['birthdate']=mysql_fetch_row($login)[4];
$_SESSION['teacherCode']=mysql_fetch_row($login)[6];
$_SESSION['active']= mysql_fetch_row($login)[8];
$_SESSION['isloggedin']= true;
}
}
else{
echo "Invalid Username/ Password";
exit();
}
}
login($username, $password);
//header('Location: ..\dashboard.html');
?>
Top Dashboard.html
<?php
include 'dbconnect.php';
session_start();
if(isset($_SESSION['isloggedin']))
{ ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="Dashboard">
<meta name="keyword" content="Dashboard, Bootstrap, Admin, Template, Theme, Responsive, Fluid, Retina">
<title>DASHGUM - FREE Bootstrap Admin Template</title>
<!-- Bootstrap core CSS -->
<link href="assets/css/bootstrap.css" rel="stylesheet">
<!--external css-->
<link href="assets/font-awesome/css/font-awesome.css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="assets/css/zabuto_calendar.css">
<link rel="stylesheet" type="text/css" href="assets/js/gritter/css/jquery.gritter.css" />
<link rel="stylesheet" type="text/css" href="assets/lineicons/style.css">
<!-- Custom styles for this template -->
<link href="assets/css/style.css" rel="stylesheet">
<link href="assets/css/style-responsive.css" rel="stylesheet">
<script src="assets/js/chart-master/Chart.js"></script>
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<section id="container" >
<!-- **********************************************************************************************************************************************************
TOP BAR CONTENT & NOTIFICATIONS
*********************************************************************************************************************************************************** -->
<!--header start-->
<header class="header black-bg">
<div class="sidebar-toggle-box">
<div class="fa fa-bars tooltips" data-placement="right" data-original-title="Toggle Navigation"></div>
</div>
Bottom Dashboard.html
</html>
<?php } ?>
dashboard.html
login.php