Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a PHP includes across multiple directories/sub directories with relative paths

Tags:

html

include

php

I'm having difficulty with paths in a cms system I'm attempting to build, I've basically got a folder with my header.php and footer.php files inside.

These are included in index.php and work fine. But then when I attempt to use the same includes in a file within my admin sub directory, the images and CSS are broken, obviously because the relative path is now wrong.

So my question is, how can I overcome this?

After reading some of the other questions on here and various other sources, I think absolute paths are the way forward, but I've always used relative paths, so the various concepts of using config files to specify an absolute path are confusing me.

I usually manage to work things out for myself, but it's been a long day and Im stumped!

like image 972
Alastair Hodgson Avatar asked Sep 28 '09 17:09

Alastair Hodgson


Video Answer


1 Answers

or...

include($_SERVER['DOCUMENT_ROOT'] .'/includes/header.php');

like image 83
catfarm Avatar answered Jan 01 '23 11:01

catfarm