php帮助用cookie隐藏导航

发布于 2024-09-02 07:58:06 字数 616 浏览 7 评论 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>   

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

if ($_COOKIE['custid'] == "admin") {

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

}

如何组合这两个脚本???

I have these tabs on my navigation:

<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>   

and I only want to show them when admin is logged in:

if ($_COOKIE['custid'] == "admin") {

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

}

How can I combine the two of these scripts???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

独孤求败 2024-09-09 07:58:06

将“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 好得多

Treating the "admin in cookie" issue as a separate issue...

<?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's inline syntax is much nicer than using {} and echos inside html

还不是爱你 2024-09-09 07:58:06
<?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 } ?>

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

<?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 } ?>

Pretty simple, put it inside the other one...

放低过去 2024-09-09 07:58:06

不太确定你的意思,但是:

<?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 来验证管理员状态。我只是为了示例而没有在这里更改它。

Not exactly sure what you mean, but:

<?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>

And I agree with @webdestroya in the comments on the post itself; you should use a session or similar instead of a cookie to verify administrator status. I just didn't change it here for the sake of the example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文