How to do you ensure the page is index.php and !isset($_GET) for nav highlighting
Question
I am making my nav links highlighted when the page is where the link points to. However, because some of my links are simply index.php with GET variables, I am having trouble differentiating that with just index.php.
E.g. index.php
and index.php?get=**
with $_SERVER['PHP_SELF']
are both /index.php
. how do I ensure that the page is at index.php without any get variables?
This is my nav highlighting code.
<?php
if( $_SERVER['PHP_SELF'] == '/index.php'
&&
! isset($_GET)
)
{ echo 'class="white"'; }
Solution
You can check if $_GET is empty like this:
if(empty($_GET)) {
// there are no GET paramas set this is index.php
} else {
// there are GET params set
}
OTHER TIPS
Because $_GET
is a (superglobal) array, you can check with count()
wether elements are set or not.
if(count($_GET) == 0) {
// index.php
} else {
// get params ...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow