$current_url = basename($_SERVER['PHP_SELF']);
考虑到我的导航(html)存储在 php 文件中并包含在每个页面中,我正在尝试使用 use来确定我在哪个页面上。这是我用来确定哪个导航选项应该处于活动状态的代码:
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/no-background.css">
<ul>
<?php
$current_url = basename($_SERVER['PHP_SELF']);
$active = "class=\"active\"";
?>
<?php if ($current_url == "globaluser.php") { ?>
<li <?php echo $active;?> > <?php } ?> <a href="globaluser.php?Agent=<?php echo $Agent;?>">Overview</a></li>
<?php if ($current_url == "search.php") { ?>
<li <?php echo $active;?> > <?php } ?> <a href="search.php?Agent=<?php echo $Agent?>">Add new client</a></li>
<?php if ($current_url == "viewadmins.php") { ?>
<li <?php echo $active;?> > <?php } ?> <a href="viewadmins.php?Agent=<?php echo $Agent?>">View admins</a></li>
<li class="border-right"><a href="emails.php?Agent=<?php echo $Agent?>">E-mails</a></li>
<li class="right border-right"><a href="logout.php"><?php echo $Agent?></a>
<ul class="drop1">
<li><a href="earnings.php?Agent=<?php echo $Agent?>">Earnings</a></li>
<li id="hover-trigger"><a href="#">Change Password</a>
<ul class="drop2">
<li>
<form action="changepass.php?Agent=<?php echo $Agent?>" method="POST">
<input type="password" name="1" placeholder="Enter new password">
<input type="password" name="2" placeholder="Repeat new password">
</li>
<li>
<input type="submit" name="changepw" class="button" value="Change">
</form>
</li>
</ul>
</li>
<li>
<form action="logout.php">
<input type="submit" class="button" value="Log out">
</form>
</li>
</ul>
</li>
但它不起作用。它将活动页面显示为活动页面,但是,它将 2 个页面显示为简单的超链接。这是它的样子:
有没有人知道为什么会发生这种情况?它适用于 2,但适用于 2,完全相同的代码?谢谢