我正在尝试包含一个头文件,但它不能像这样工作:
<?php
include 'includes/header.php';
?>
这就是我在页面上的内容,我在网站的每一页上都收到了这个错误:
注意:未定义索引:在第14行登录C:\ xampp \ htdocs \ deWaai \ includes \ header.php
这是header.php中的代码:
<!DOCTYPE html>
<html>
<?php
include 'head.php';
?>
<body>
<div>
<?php
include "./functions/connection.php";
//kijken of de gebruiker is ingelogd
if($_SESSION['logged'] == 1) {
//admin
if($_SESSION['userlevel'] == 1) {
include 'includes/adminmenu.php';
//medewerker
} elseif ($_SESSION['userlevel'] == 2) {
include 'includes/medewerkermenu.php';
//cursist
} else {
include 'includes/cursistmenu.php';
}
} else {
include 'includes/menu.php';
}
?>
</div>
head.php中的php代码:
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Zeilschool De Waai</title>
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.3.1/css/swiper.min.css">
<link rel="stylesheet" href="assets/css/styles.css">
<link rel="stylesheet" href="assets/css/Navigation-Clean1.css">
<link rel="stylesheet" href="assets/css/Navigation-with-Button1.css">
<link rel="stylesheet" href="assets/css/Simple-Slider.css">
<link rel="stylesheet" href="assets/fonts/ionicons.min.css">
<script src="assets/js/jquery.min.js"></script>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.3.1/js/swiper.jquery.min.js"></script>
<script src="assets/js/Simple-Slider.js"></script>
</head>
我做错了什么,为什么我不能在我的网站上的所有页面上都包含header.php? 任何形式的帮助表示赞赏 我正在使用Xampp apache服务器。 (deWaai是我项目的名称) (head和header.php都在我的include文件夹中,如下所示:htdocs - &gt; deWaai - &gt; includes&gt;
感谢任何形式的帮助,thx
答案 0 :(得分:2)
将header.php
文件替换为:
<!DOCTYPE html>
<html>
<?php
include 'head.php';
?>
<body>
<div>
<?php
include "./functions/connection.php";
//kijken of de gebruiker is ingelogd
if(isset($_SESSION['logged']) && $_SESSION['logged'] == 1) {
//admin
if($_SESSION['userlevel'] == 1) {
include 'includes/adminmenu.php';
//medewerker
} elseif ($_SESSION['userlevel'] == 2) {
include 'includes/medewerkermenu.php';
//cursist
} else {
include 'includes/cursistmenu.php';
}
} else {
include 'includes/menu.php';
}
?>
</div>
在检查其值之前,请务必检查会话是否已设置,以防止出现类似错误。