我正在创建一个带有单个 index.php 文件的网站,其中包含 2 个标头。我正在使用“include”语句来在索引上调用标头。“header1.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条经验 获得超15个赞
可能是这个
if ($_SESSION['user'] && $_SESSION['user'] == 1) {
include 'header2.php';
}else{
include 'header1.php';
}
- 1 回答
- 0 关注
- 75 浏览
添加回答
举报
0/150
提交
取消