douping3891 2014-02-19 13:34
浏览 39
已采纳

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>
  • 写回答

2条回答 默认 最新

  • doueta6642 2014-02-19 14:57
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程