nicezeal
nicezeal

Reputation: 43

PHP_SELF returning 's' string on localhost

I am using this code to highlight the active link in navigation, but the code is not working. When I echo $_SERVER['PHP_SELF'] this, it gives 's' string as the output on localhost. Please help, what is wrong here?

P.S. Also when I checked apache error.log it is showing:

[Wed Feb 19 18:28:08.671229 2014] [:error] [pid 1353] [client 127.0.0.1:57968] PHP Warning:  Illegal string offset 'PHP_SELF'

I'm using Ubuntu 13.10.

<li <?php if($_SERVER['PHP_SELF'] == "index.php"){ echo 'class="active"';}?> > <a href="index.php"><i class="fa fa-dashboard"></i> Dashboard</a></li>

Upvotes: 3

Views: 576

Answers (2)

Sagar Guhe
Sagar Guhe

Reputation: 1106

As you have mentioned in your last comment, you used the PHP_SELF in the header.php file so the which is calling PHP_SELF, it returns that filename. So use that in your index.php file at the top of every code:

<?php $filename = basename($_SERVER['PHP_SELF']);?>

and then use the $filename variable in your header.php file. may be this will help. let me know if this works.

Upvotes: 3

Ankit Pise
Ankit Pise

Reputation: 1259

<li <?php if(substr($_SERVER['PHP_SELF'], 1) == "index.php"){ echo 'class="active"';}?> > <a href="index.php"><i class="fa fa-dashboard"></i> Dashboard</a></li>

Check if this works for you.

Upvotes: 0

Related Questions