我希望我的代码仅在我以管理员身份登录时显示此内容 我已经为它编写了这段代码,但当我添加类似
的内容时除外<a href=""></a>
在 php 代码中它崩溃了
所以当我使用时:
</html>
//check if logged in
<?php
session_start();
$loggedin = $_SESSION['loggedin'];
$loggedinadmin = $_SESSION['positief'];
?>
//or do i have to use the code below to check if logged in (i can leave out the if ($loggedin)
<?php
session_start(); // Start the session
$loggedin = $_SESSION['loggedin']; // Are they loggedin?
// They are not logged in, Kill the page and ask them to login.
if ($loggedin != "1") {
die('Sorry you are not logged in, please click <a href="testlogin.php">Here</a> to login');}
$logadmin = $_SESSION['logadmin']; // Are they loggedin?
// They are not an admin, Kill the page and ask them to login.
if ($logadmin != "1") {
die('You have no POWER here! click <a href="test.html">Here</a> return to your shell');}
//in the line above does it need an edit? so it doesn't show the items you have no rights for?
?>
// css code
<head>
<link href="style2.css" type="text/css" rel="stylesheet"/>
</head>
//nav bar and links
<div id="nav">
<div id="nav_wrapper">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Login</a></li>
<li><a href="#">Edit App</a></li>
<li><a href="#">Preview</a></li>
<li><a href="#">Logout</a></li>
//EXEPTION for admin
<?php
$adminit="IT Admin";
$verzend="Verzendingen";
$verzond="Verzonden";
$magazij="Magazijn";
if ($loggedinadmin) {
echo "<li>$adminit</li>";
echo "<li>$verzend</li>";
echo "<li>$verzond</li>";
echo "<li>$magazij</li>";
}
?>
</ul>
</div>
</div>
</html>
这是我的代码,我做了一些通知来解释我做了什么。 或寻求建议。
任何花时间查看此内容并尝试提供帮助的人提前致谢!
问候,
DTcodedude
最佳答案
您可以像这样在 html 代码中添加 php 代码。
<li><a href="<?php echo $url; ?>"><?php echo $adminIT; ?></a></li>
关于php - 导航栏问题 : only show links in nav bar when logged in as admin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22219533/