Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Go back a folder in php

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use your DOCUMENT_ROOT as the starting point for all your includes and requires… That way it will be portable between dev and production as well.

Here you can read about $_SERVER

IE

include_once $_SERVER["DOCUMENT_ROOT"] . '/public/foo/bar/includes/header.inc.php';
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading