Good day! I really need someone's help here. I have a hard time thinking about how to execute the right code.
I am creating a website with a single index.php file wherein it consists of 2 headers. I am using "include" statement for the header to be called on the index. "header1.php" is the default header for the guests of the websites which also consist of "LOGIN" button. While "header2.php" is the header for those who have logged in their account and have a "LOGOUT" button.
The problem is, when the guest visits the websites, the websites will show the default header which is "header1.php". And when the user log in to his/her account, the "header2.php" will show. How should i suppose to call the header? What condition should I write inside the if else statement? It will probably need an access to the MySQL Database for the user's data.
Example:
<?php
if( user log in to his account ){
include 'header2.php';
}else{
include 'header1.php';
}
my log in script is:
<?php
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
$connect = mysqli_connect("localhost", "root", "", "yfcgk_canlaon");
$query = mysqli_query($connect, "SELECT * from members WHERE USERNAME = '$username' and PASSWORD = '$password'");
$count = mysqli_num_rows($query);
if($count <= 0 ){
session_start();
header("location:index.php?error");
}else{
$_SESSION['user'] = 1;
$_SESSION['username'] = ucwords($username);
header("location:index.php");
}
?>