我正在創建一個帶有單個 index.php 文件的網站,其中包含 2 個標頭。我正在使用“include”語句來在索引上調用標頭?!癶eader1.php”是網站訪客的默認標頭,其中還包含“登錄”按鈕。而“header2.php”是那些已登錄其帳戶并具有“注銷”按鈕的標題。問題是,當訪客訪問網站時,網站將顯示默認標頭“header1.php”。當用戶登錄他/她的帳戶時,將顯示“header2.php”。我應該如何調用標題?if else 語句中應該寫什么條件?它可能需要訪問 MySQL 數據庫來獲取用戶數據。例子:<?phpif( user log in to his account ){ include 'header2.php';}else{ include 'header1.php';}我的登錄腳本是:<?phpsession_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");}?>
1 回答

侃侃爾雅
TA貢獻1801條經驗 獲得超16個贊
可能是這個
if ($_SESSION['user'] && $_SESSION['user'] == 1) {
include 'header2.php';
}else{
include 'header1.php';
}
- 1 回答
- 0 關注
- 113 瀏覽
添加回答
舉報
0/150
提交
取消