dragon0023 2011-06-15 00:33
浏览 54
已采纳

如何定义“系统范围”常量,该常量是包含特定文件夹目录的字符串?

I store all of my scripts in the same place on the server and reference then using PHP include statements. But what if I want or need to change that directory? Do I really want to change every statement? Absolutely not.

One thing that I debated doing was to include a file named 'scriptsdir.php' that would be in the home directory for easy access. All this file would be responsible of doing is to define the constant 'SCRIPTS_DIR' as that directory. This suffices but if THAT file has to be moved or something happens to it, etc. I was wondering if I could define a constant that would be accessible without ever having to manually define it.

Is there a way to do this in php.ini or .htaccess or anything?

  • 写回答

3条回答 默认 最新

  • dongpa6867 2011-06-15 01:12
    关注

    Another option is to declare a variable $_SERVER["SCRIPTS_DIR"] via .htaccess using:

     SetEnv SCRIPTS_DIR /var/www/project123/includes/
    

    That would be available reliably to all scripts beneath the document_root and can often simplify relocations.

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

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集