dongxiang3648 2008-12-27 14:49
浏览 15
已采纳

PHP set_inlude_path并包含最佳实践

Where would

set_include_path("../../");

point to?

I am trying to run some PHP code on a standard XAMPP server. And put my stuff into the htdocs folder. The includes point to relative paths, But it does not work. Is there any best-practise for includes? The code has to run on machines of multiple developers.

  • 写回答

2条回答 默认 最新

  • dporb84480 2008-12-27 15:50
    关注

    Relative path should work fine (warning: apache on windows, as I know, don't follow the simlinks, or whatever are called on that os).

    Maybe you should use the syntax (in order to avoid problem with different php versions)

    ini_set('include_path', 'yourdir');
    

    and test the return value to see if all is ok.

    Turning to the best practices: To me setting an configuration directive into a script, expecially if project-wide, is wrong, or at least dangerous.

    A better practice is to put the directive into the .htaccess file in the directory that contains your php files project.

    Even better, it is faster, put the directives into the appropriate virtualhost section of your apache config. For develop, though, .htaccess is more flexible and therefore preferable.

    It should be something like this: php_value include_path ".:../..:<your path collection>"

    Doing this lets you share the php configuration w/o have fiddling with the ini_set directive in every php file you write.

    Not to mention that if you have a special file that needs a custom include_path, you can set it in the file and this will be evident to everyone at a very rapid glance.

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

报告相同问题?

悬赏问题

  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动