root path doesn't work with php include

Per Magnusson picture Per Magnusson · Sep 9, 2009 · Viewed 64.8k times · Source

/ in the beginning of a link to get to the root folder doesn't work in php include.

for example "/example/example.php"

What is the solution?

Answer

Paul Dixon picture Paul Dixon · Sep 9, 2009

I'm assuming by root folder you mean your web document root, rather than filesystem root.

To that end, you can either

  • add the web root folder to the include path, and include('example/example.php')
  • or you can include($_SERVER['DOCUMENT_ROOT'].'/example/example.php')