社区首页 >问答首页 >php帮助使用cookie隐藏导航

php帮助使用cookie隐藏导航
EN

Stack Overflow用户
提问于 2010-05-19 22:59:02
回答 3查看 78关注 0票数 0

我的导航上有以下选项卡:

代码语言:javascript
代码运行次数:0
复制
<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>   

我只想在管理员登录时显示它们:

代码语言:javascript
代码运行次数:0
复制
if ($_COOKIE['custid'] == "admin") {

echo "Customers";
echo "Trunks";
echo "Settings";

}

我如何结合这两个脚本?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-05-19 23:10:14

代码语言:javascript
代码运行次数: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 } ?>

很简单,把它放在另一个里面...

票数 0
EN

Stack Overflow用户

发布于 2010-05-19 23:14:46

将“管理在cookie中”的问题作为一个单独的问题...

代码语言:javascript
代码运行次数:0
复制
<?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要好得多

票数 1
EN

Stack Overflow用户

发布于 2010-05-19 23:05:51

我不太清楚你的意思,但是:

代码语言:javascript
代码运行次数: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来验证管理员状态。我只是为了这个例子而没有在这里更改它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2870033

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文