当链接指向页面时,我会突出显示我的导航链接。然而,因为我的一些链接只是带有GET变量的index.php,所以我很难用index.php来区分它。
例如,index.php
和具有$_SERVER['PHP_SELF']
的index.php?get=**
都是/index.php
。如何确保页面在没有任何get变量的情况下位于index.php?
这是我的导航高亮代码。
<?php
if( $_SERVER['PHP_SELF'] == '/index.php'
&&
! isset($_GET)
)
{ echo 'class="white"'; }
您可以检查$_GET是否为空,如下所示:
if(empty($_GET)) {
// there are no GET paramas set this is index.php
} else {
// there are GET params set
}
因为$_GET
是一个(超全局)数组,所以可以使用count()
检查元素是否已设置。
if(count($_GET) == 0) {
// index.php
} else {
// get params ...
}