我的导航中有这些标签:
<li<?php if ($thisPage=="Customers") echo " class=\"current\""; ?>><a href="/customers/">Customers</a></li>
<li<?php if ($thisPage=="Trunks") echo " class=\"current\""; ?>><a href="/trunks/">Trunks</a></li>
<li<?php if ($thisPage=="Settings") echo " class=\"current\""; ?>><a href="/settings/">Settings</a></li>
我只想在管理员登录时显示它们:
if ($_COOKIE['custid'] == "admin") {
echo "Customers";
echo "Trunks";
echo "Settings";
}
如何组合这两个脚本???
答案 0 :(得分:1)
将“admin in cookie”问题作为一个单独的问题处理......
<?php if($admin): ?>
<li<?php if ($thisPage=="Customers"): ?> class="current"<?php endif; ?>><a href="/customers/">Customers</a></li>
<li<?php if ($thisPage=="Trunks"): ?> class="current"<?php endif; ?>><a href="/trunks/">Trunks</a></li>
<li<?php if ($thisPage=="Settings"): ?> class="current"<?php endif; ?>><a href="/settings/">Settings</a></li>
<?php endif; ?>
PHP的内联语法比使用html
中的{}和回声更好答案 1 :(得分:0)
不完全确定你的意思,但是:
<?php
if ($_COOKIE['custid'] == "admin") { ?>
<li<?php if ($thisPage=="Customers") echo " class=\"current\""; ?>><a href="/customers/">Customers</a></li>
<li<?php if ($thisPage=="Trunks") echo " class=\"current\""; ?>><a href="/trunks/">Trunks</a></li>
<li<?php if ($thisPage=="Settings") echo " class=\"current\""; ?>><a href="/settings/">Settings</a></li>
<?php } else { ?>
<li><a href="/customers/">Customers</a></li>
<li><a href="/trunks/">Trunks</a></li>
<li><a href="/settings/">Settings</a></li>
<?php } ?>
// OR
<li<?php if ($_COOKIE['custid'] == "admin" && $thisPage=="Customers") echo " class=\"current\""; ?>><a href="/customers/">Customers</a></li>
<li<?php if ($_COOKIE['custid'] == "admin" && $thisPage=="Trunks") echo " class=\"current\""; ?>><a href="/trunks/">Trunks</a></li>
<li<?php if ($_COOKIE['custid'] == "admin" && $thisPage=="Settings") echo " class=\"current\""; ?>><a href="/settings/">Settings</a></li>
我同意帖子本身的评论中的 @webdestroya ;您应该使用会话或类似的而不是cookie来验证管理员状态。我只是为了这个例子而没有在这里改变它。
答案 2 :(得分:0)
<?php
if ($_COOKIE['custid'] == "admin") { ?>
<li<?php if ($thisPage=="Customers") echo " class=\"current\""; ?>><a href="/customers/">Customers</a></li>
<li<?php if ($thisPage=="Trunks") echo " class=\"current\""; ?>><a href="/trunks/">Trunks</a></li>
<li<?php if ($thisPage=="Settings") echo " class=\"current\""; ?>><a href="/settings/">Settings</a></li>
<?php } ?>
非常简单,把它放在另一个......