开发者

Using $_server['document_root'] on localhost/the wild web

开发者 https://www.devze.com 2023-03-19 22:55 出处:网络
On my WAMP setup, I\'m using $_server[\'document_root\'] in a number of filepaths.. I had been using a static $ROOT variable, but thought it would be nice not to have to edit开发者_运维问答 that const

On my WAMP setup, I'm using $_server['document_root'] in a number of filepaths.. I had been using a static $ROOT variable, but thought it would be nice not to have to edit开发者_运维问答 that constant when uploading the site.

Unfortunately, on my WAMP setup, $_server['document_root'] is being defined as 'C:/wamp/www/' and none of the links seem to be working under WAMP on Windows (though they were fine on MAMP on Mac when I initially made the change). It's looking in file:///C:/wamp/www.

I had read an article that was espousing the virtues of document_root for security reasons and ease of use. Is it really recommended, though? It occurs to me that it could be something different depending on the installation.

I'm thinking of just defining the document_root variable, but now I'm wondering whether it's reliable to use the variable at all.


I don't have experience with WAMP, but do have experience with $_SERVER['DOCUMENT_ROOT'] and alternatives. I've found $_SERVER['DOCUMENT_ROOT'] to be the most reliable relative path to work from in an application.

The Reserved Variables documentation has quite a few comments on $_SERVER['DOCUMENT_ROOT'] related to windows (most specifically to IIS though, not WAMP)

http://www.php.net/manual/en/reserved.variables.php#45229

It sounds to me like your DocumentRoot for your site is pointing to C:/wamp/www/ and not the subfolder for your domain within www/. You can learn about Apache's DocumentRoot here.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号