我是 php 编码的新手,我希望你能帮助一个 java 男孩摆脱困境。
我尝试在“index.php”中动态包含导航菜单和内容。如果 Í 测试下面的代码,我只会再次得到相同的 index.php,而无需更改导航菜单,这在我看来应该会发生,但也许我对 php 的了解不够好。
我的index.php:
<?php
//^ E_NOTICE ^ E_WARNING
error_reporting(E_ALL);
if (!defined("ABS_PATH"))define("ABS_PATH", $_SERVER['DOCUMENT_ROOT']);
if (!isset($_SESSION['login'])) {
session_start();
$_SESSION['login'] = 1;
$_SESSION['role'] = "guest";
$_SESSION['navi'] = "/view/navigation_guest.php";
$_SESSION['content'] = "/view/content_login.php";
$_SESSION['calendar'] = "/view/calendar.php";
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Klausurplaner</title>
<link href="view/design.css" type="text/css" rel="stylesheet">
</head>
<body>
<div id="frame">
<div id="header">
<?php
include_once "/view/header.php";
?>
</div>
<div id="main">
<div id="navi">
<ul>
<?php
include_once $_SESSION['navi'];
?>
</ul>
</div>
<div id="content">
<?php
include_once $_SESSION['content'];
?>
</div>
<div id="calendar">
<?php
include_once $_SESSION['calendar'];
?>
</div>
</div>
</div>
</body>
</html>
如果我尝试使用以下内容修改 index.php,如上所述,我只会再次获得相同的网站,而无需更改导航菜单。
content_login.php:_
<?php
if (!defined("ABS_PATH"))define("ABS_PATH", $_SERVER['DOCUMENT_ROOT']);
include_once(ABS_PATH . "/Klausurplaner/Control/LoginControl.php");
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link href="design.css" type="text/css" rel="stylesheet">
</head>
<body>
<h1>Bitte loggen Sie sich ein.</h1>
<form method="post" action="control/btnLoginClicked.php">
<p1>Benutzername:</p1>
<br>
<input id="edt_username" type="text" size="25%"/>
<br>
<p1>Passwort:</p1>
<br>
<input id="edt_password" type="password" size="25%"/>
<br><br>
<input name="btn_login" type="submit" value="login" size="5%"/>
</form>
<br><br>
<!-- <br><br>
<a href="content_guest_newPassword.php">Passwort vergessen</a>
<!-- E-Mail an die eigene E-Mail-Adresse mit neuem PW -->
</body>
</html>
btnLoginClicked.php:_
<?php
if (!defined("ABS_PATH"))define("ABS_PATH", $_SERVER['DOCUMENT_ROOT']);
/**
* @author Falk Libor
* @version 1.0
*
* Date: 19.03.2013
*/
if (isset($_POST['btn_login'])) {
$_SESSION['navi'] = "/view/navigation_admin.php";
$path = ABS_PATH . "/Klausurplaner/index.php";
header("Location: " . $path);
exit();
}
?>
编辑: session_start() 现在在 if 块之前,但不知何故,在我单击“content_login.php”中的“btn_login”之前,它现在显示“navigation_admin.php”而不是定义的“navigation_guest.php”。有什么想法吗?