开发者

Relative Web path vs Absolute path

this is a 3 part question

Is there any performance or security risk in relative path ?

How can i convert relative path to absolute path [in a开发者_如何学编程 large project written in PHP] ?

in PHP when using include should i give the absolute path or the relative path ?


There are two kinds of relative paths in PHP. Relative paths according to the filesystem start with ./ or ../ and do not impact performance. PHP also interprets relative paths like what/ever.php specially itself and takes the include_path into account for those. That's usually (measurably) slower since directories have to be traversed and searched.

Security, that's too broadly asked, does not directly play into that. And if there are possibly malicious include scripts placed elsewhere on the system and within the include_path, then I would consider that the actual problem, not the relative paths.

What you should use in your project, depends on if it needs to be relocatable. It's most common to simulate absolute paths using a constant ala PROJECT_ROOT.

To transform a filesystem-relative path into an absolute, use realpath()

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜