我正在創(chuàng)建一個(gè)帶有單個(gè) index.php 文件的網(wǎng)站,其中包含 2 個(gè)標(biāo)頭。我正在使用“include”語句來在索引上調(diào)用標(biāo)頭?!癶eader1.php”是網(wǎng)站訪客的默認(rèn)標(biāo)頭,其中還包含“登錄”按鈕。而“header2.php”是那些已登錄其帳戶并具有“注銷”按鈕的標(biāo)題。問題是,當(dāng)訪客訪問網(wǎng)站時(shí),網(wǎng)站將顯示默認(rèn)標(biāo)頭“header1.php”。當(dāng)用戶登錄他/她的帳戶時(shí),將顯示“header2.php”。我應(yīng)該如何調(diào)用標(biāo)題?if else 語句中應(yīng)該寫什么條件?它可能需要訪問 MySQL 數(shù)據(jù)庫來獲取用戶數(shù)據(jù)。例子:<?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貢獻(xiàn)1801條經(jīng)驗(yàn) 獲得超16個(gè)贊
可能是這個(gè)
if ($_SESSION['user'] && $_SESSION['user'] == 1) {
include 'header2.php';
}else{
include 'header1.php';
}
- 1 回答
- 0 關(guān)注
- 110 瀏覽
添加回答
舉報(bào)
0/150
提交
取消