Hi,

I'm new here so first i would like to say hello to everyone :)

I have been learning PHP for the past year on and off and have built a fully pledged website. Since my website first launched it has progressed into a full membership system which i love as it was part of my learning curve.

Since then i have obviously learned allot more about PHP althou i would still say i am not a pro or anything as i say i been learning on and off due to issues beyond my control so i could not learn as much as i wanted to.

Anyway, i basically want to re develop the backend of my live website. To ensure it goes well i am redoing the backend of the site on my computer using XAMPP etc. As since i started to learn i know know from learning that i could improve majority of my code. Security wise i am happy with as i always made sure i learnt that at the begging, i mean just doing code cleanup.

Basically i am not sure how to go about it.

i use includes obviously so i can make updates via one file. Problem is i am not sure how to proceed.

my pages when i create them for my website have a structure template like:

<!-- Include top.inc.php  -->
<?php require_once("".$_SERVER['DOCUMENT_ROOT']."/inc/top.inc.php"); ?>

<!-- Meta Description -->
<meta name="description" content="" />

<!-- Keywords -->
<meta name="keywords" content="" />

<!-- Page Title -->
<title></title>

</head>

<!-- Include main.inc.php  -->
<?php require_once("".$_SERVER[DOCUMENT_ROOT]. "$main_inc"); ?>

<!-- Include menu.inc.php  -->
<?php require_once("".$_SERVER[DOCUMENT_ROOT]. "$menu_inc"); ?>

<!-- PLACE WEBSITE CONTENT HERE -->

<!-- PLACE WEBSITE CONTENT HERE END -->

<!-- Include footer.inc.php  -->
<?php require_once("".$_SERVER[DOCUMENT_ROOT]. "$footer_inc"); ?>

Now problem i got is each page i create needs the top.inc include path but the others don't as the top.inc.php has an include to paths.inc.php that contains site paths for things like main.inc.php and other paths across the website.

Basically i am trying to create my website so i can avoid includes in my webpages i create so when and if i do change server and/or path(s) i only have to change it in one place. Problem is as i got an include for top.inc.php in my webpage template that i use to create my webpages it means if i ever change the path etc i have to manually edit every page.

I am really not sure how to proceed.

Should i keep my paths.inc.php (which contains paths for website) or is there a better alternative way?

At the moment all my files that are needed on different page like website paths, website name, address etc i have placed in includes in the top.inc.php . Problem is my functions.php file for example has an authentication function, i cannot include this in top.inc.php because it needs to go before top.inc.php so it can exit script before it loads page. This means i would be putting another include in my webpages which means if i change paths etc i will have to change each webpage indvidually.

I am so confused how to go about my includes and paths etc.

If anyone could explain to me how they do it and an efficent way i would be so grateful as this is causing me delay on not being able to start my re-programming of my website.

Truth of the matter is without confusing you anymore as i probably not explained it in simple terms is how do you go about your includes, paths etc?

Thanks
PHPLOVER

Recommended Answers

All 3 Replies

If you use a relative address like include "inc/xxxx.php" or one that points to the root like $_SERVER... I don't see why you would need to change it. I don't understand why you would anticipate a need to totally change the structure. Once you define a need to have $_SERVER."/inc/top.inc.php" then that becomes a requirement for your site. Unless I am misunderstanding your question, it seems that you are trying to be unnecessarily flexible.

Includes are the right way to go
the file is processed as a single file includes are not separate
if the validation authentication were the first lines in include.php they are processed first, no part of the page is output to the browser untill after that include
the exit will always take place before browser output as long as only php functions that do not output to screen are in those include files
your worries seem to be baseless
changing back to no-include files would be an extreme retrograde step and increase the number of edits to individual pages not decrease them

Hi,

Thanks for your replies.

Reason why is at the moment i got includes in page using $_SERVER .

When i download the backup from my website onto local and load in xampp for example the document root is messed up, instead of being like for example htdocs/site_folder/includes/top.inc.php it shows in xampp as htdocs/includes/top.inc.php missing the folder where my site is in.

But to solve this i just placed my entire site in the htdocs instead on a folder in htdocs, maybe there is a setting i am missing althou i have searched and looked it up on there website.

But i am keeping to includes anyway, i certainly would not change that as they are a god send to any developer. I have finally today came up with an option to be able to include everything i want on my pages and only requiring 1 file edit.

I think i may have explained it a bit wrong but i have figured it out now.

Thanks for the help :)

PHPLOVER

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.