PHP_SELF在localhost上返回's'字符串

PHP_SELF在localhost上返回's'字符串

问题描述:

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>

我使用此代码突出显示导航中的活动链接,但代码无效。 当我 echo $ _SERVER ['PHP_SELF'] code>时,它将's'字符串作为localhost的输出。 请帮忙,这里有什么问题? p>

P.S。 此外,当我检查apache error.log时,它显示: p>

  [Wed Feb 19 18:28:08.671229 2014] [:error] [pid 1353] [client 127.0.0.1  :57968] PHP警告:非法字符串偏移'PHP_SELF'
  code>  pre> 
 
 

我正在使用Ubuntu 13.10。 p>

   &lt; li&lt;?php if($ _ SERVER ['PHP_SELF'] ==“index.php”){echo'class =“active”';}?&gt;  &GT;  &lt; a href =“index.php”&gt;&lt; i class =“fa fa-dashboard”&gt;&lt; / i&gt; 信息中心&lt; / a&gt;&lt; / li&gt; 
  code>  pre> 
  div>

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.

<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.