Reputation: 17530
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 ?
Upvotes: 0
Views: 1200
Reputation: 145482
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()
Upvotes: 3