2

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>
Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
nicezeal
  • 33
  • 5
  • We can use php code any where in the HTML :-) – nicezeal Feb 19 '14 at 13:41
  • yes in the html, but this is within the
  • tag, put it in front of it or behind it or something.
  • – Goos van den Bekerom Feb 19 '14 at 13:42
  • @Goosebumbs your comments are not legit. You can use PHP anywhere in HTML(as long as the extension is PHP or your Apache settings are edited to accept PHP in other extension). – GuyT Feb 19 '14 at 13:45
  • @nevermind like I said, I don't think it will solve the problem. but I'm pretty sure some browsers won't properly run this code. – Goos van den Bekerom Feb 19 '14 at 13:46
  • @user3328295 Could you give the output? You've certainly forgot a space before `class="active"` – GuyT Feb 19 '14 at 13:46
  • @Goosebumbs I've made a fiddle for you to prove it: http://phpfiddle.org/main/code/ju1-v0g – GuyT Feb 19 '14 at 13:48
  • @GuyT I like how you try to proof something and you don't even close your
  • opening tag.
  • – Goos van den Bekerom Feb 19 '14 at 13:50