我的导航上有以下选项卡:
<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";
}
我如何结合这两个脚本?
发布于 2010-05-19 23:10:14
<?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 } ?>
很简单,把它放在另一个里面...
发布于 2010-05-19 23:14:46
将“管理在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中使用{}和echo要好得多
发布于 2010-05-19 23:05:51
我不太清楚你的意思,但是:
<?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来验证管理员状态。我只是为了这个例子而没有在这里更改它。
https://stackoverflow.com/questions/2870033
复制相似问题