i know my question seems a bit vague but an example will do wonders.
For example :
When you go into a folder you use : <?php include_once 'includes/header.inc.php' ?>
when you want to go back one you use ../../ to go back you get the idea. However is there by chance a better way of doing this cuz i’ve found it’s easy to break?
vague but i hope someone can help, thanks in advance.
I’ve obviously tried the ../ to go back to parent directory or folder. When i google i tend to find how to go back using header etc but i dont think that’ll help me much.
2
Answers
Use your
DOCUMENT_ROOT
as the starting point for all yourincludes
andrequires
… That way it will be portable between dev and production as well.Here you can read about $_SERVER
IE
Rather than basing everything off of the document root, which is not necessarily the root of your actual project, nor is it populated outside of an HTTP context, I generally do the following.
In a config file for which you definitely know the location relative to your application’s root:
and, for good measure: