2

I am about to use an old software I wrote when I had very little knowledge about PHP and now I have a lot of:

require("/path/file.php");

that do not work anymore because $_SERVER['DOCUMENT_ROOT'] has changed from "/" to "/htdocs/web/". Is there anything I can do instead of changing every line of code? I don't have access to httpd.conf but I can create .htaccess file and edit php.ini. Any help is appreciated.

  • thank you, could you give me an example? `set_include_path("/htdocs/web/");` is that right? – silentheaven Apr 13 '19 at 18:29
  • If you have a common config file you can overwrite `$_SERVER['DOCUMENT_ROOT']` to contain the value you want: `$_SERVER['DOCUMENT_ROOT'] = '/';`; It's not a best practice but neither is using `$_SERVER['DOCUMENT_ROOT']` for includes. – John Conde Apr 13 '19 at 18:39
  • 2
    Changing `include_path` won't help because it's an absolute path. You'll have to update your source code files. This should be fairly trivial using `grep -rl` to get a list of the files with that text, and then running them through `sed` to do the replacement. – miken32 Apr 13 '19 at 18:39
  • I do have a common config file but neither overwriting $_SERVER['DOCUMENT_ROOT'] to "/" or set_include_path("/htdocs/web/"); worked. – silentheaven Apr 13 '19 at 18:45
  • Possible duplicate of [can I change value of $\_SERVER\['DOCUMENT\_ROOT'\]?](https://stackoverflow.com/questions/8364069/can-i-change-value-of-serverdocument-root) – slevy1 Apr 13 '19 at 19:27

0 Answers0