php - 导航栏问题 : only show links in nav bar when logged in as admin

标签 php html css admin

我希望我的代码仅在我以管理员身份登录时显示此内容 我已经为它编写了这段代码,但当我添加类似

的内容时除外
<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/

相关文章:

javascript - 打印 HTML 页面(整页!)

jquery - 需要帮助定位 Canvas 元素

css - 将类添加到 jQuery 日期选择器

php - 如何设置 cookie 20 分钟并检查它们是否过期

php - 如何使用 PHP 将数字月份数字转换为月份名称

PHP openssl_public_加密 “key parameter is not a valid key”

javascript - 如何在打开模式对话框时禁用控件单击事件

Php - 理解 create_function() - 传递简单变量

html - 模式弹出时使屏幕变暗

css - SASS & LESS - 扩展一个单独的类