Skip to content
Advertisement

How to get absolute path to public_html folder

I’m a little confused about absolute paths when searching in the questions. I have a php project that includes a Header.php file which is the header for first level php files. To avoid adding another header, I want to make that work for the inner levels, too. For example use it in a php file that is included in another folder of project. To do this, I wana get the absoute path to my public_html folder and use that in my Header.php. How can I get it?

Advertisement

Answer

Use / at the start.

include('/header.php');

This will always include the header.php from the root folder.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement