导航栏问题:仅在以管理员身份登录时显示导航栏中的链接

时间:2014-03-06 08:59:26

标签: 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

2 个答案:

答案 0 :(得分:0)

你可以在你的html代码中添加你的php代码。

<li><a href="<?php echo $url; ?>"><?php echo $adminIT; ?></a></li>

答案 1 :(得分:0)

OP解决方案。

<html>


<?php
session_start();
$loggedin = $_SESSION['loggedin'];
$logadmin = $_SESSION['logadmin'];// checks if you got adminrights
// (if intrested in auth code post below).

$home="index.php";
$login="login.php";
$edit="navbase.php";
$preview="preview.php";
$logout="logout.php";

$adminit="adminbase.php";
$verzend="verzend.php";
$verzond="verzonden.php";
$magazij="magbase.php";
$host="";
$username="";
$password="";
$db_name="";

$conn = mysql_connect("$host", "$username", "$password")or die("cannot connect Host");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM users";

$result = mysql_query($sql, $conn);

?>

<head>
<link href="style2.css" type="text/css" rel="stylesheet"/>
</head>

<div id="nav">
<div id="nav_wrapper">
<ul>

<?

if ($result) {

echo " <li><a href=\"$home\">Home</a></li>";
echo " <li><a href=\"$login\">Login</a></li>";
echo " <li><a href=\"$edit\">Edit App</a></li>";
echo " <li><a href=\"$preview\">Preview</a></li>";
echo " <li><a href=\"$logout\">Logout</a></li>";

} else {

die ('crash');

}
?>
<?

if ($logadmin) {

echo " <li><a href=\"$adminit\">IT Admin</a></li>";
echo " <li><a href=\"$verzend\">Verzendingen</a></li>"; 
echo " <li><a href=\"$verzond\">Verzonden</a></li>";
echo " <li><a href=\"$magazij\">Magazijn</a></li>";

}else{


}

?>

</ul>

</div>
</div>


</html>