douwuli4512 2010-04-16 02:26
浏览 77
已采纳

使用绝对路径更容易修改包括将来的路径?

config.php put at the root level, this file will be included in any pages.

Then at config.php

<?php
define( 'ROOT_DIR', dirname(__FILE__) );
?>

So at all other pages from different sub/a.php , sub/sub/b.php directories, when I want to include a specific file in specific location, I just need to

include( ROOT_DIR.'/include/functions.php' );

In windows server, the ROOT_DIR bring the value to C:/inetpub/vhosts/domain.com

Is this a good/secure way?

It seems like via this way, when I move the b.php to other upper level folder, I don't need to do any changes to the include file path, which is good for maintenance.

Any cons? Like SEO wise, or any other reason... What you guys think.

  • 写回答

3条回答 默认 最新

  • doubo3384 2010-04-16 03:10
    关注

    I will comment that one advantage to the method you're using (using absolute paths) is that PHP won't need to resolve the path for every request. You may see ever-so-slightly better performance that way.

    Also, if you're using PHP 5.3, you can just use __DIR__ instead of dirname(__FILE__).

    If you're not using 5.3, you might give it a shot if you can. A lot of improvements were made for the Windows platform in 5.3, not to mention the many new useful language features.

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

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献