Jump to content

functions on include


onlyican

Recommended Posts

Hey guys

No code here, just best practice

Lets explain how I set up a website

I create a file which is the header and include
This file contains the doctype, head, and anything in the body that aint the content (navigation ect)
and the div for the content

THen I have a footer file
On here, I have, well, my footer, and close all htm tags

Then on the main page I have something like
[code]
<?php
$page_title = "My Page";
require("inc/myheadefile.php");

echo "Hello and welcome, this is the content, all ready to go";

require("inc/myfooterfile.php");
?>
[/code]


NOW
I make a lot of functions
Every form on my websites are in functions
This way I can do something like
[code]
<?php
if($_POST["fieldname"]){
if($_POST["CheckAllFieldsAreCompletedInAnIfStatement"]){

}else{
echo "Cant you complete a simple form<br />\n";
ShowForm();
}
}else{
ShowForm();
}
?>
[/code]
(I dont have a field that long, each Cap letter is a new word, look closley)
WIth me so far

All this is so my question makes sence

The form functions, I create the function at the top of THAT page, as I am only going to call it on that page

BUT
I have functions, they I may call on every page (I have a function to connect to the DB, which is on most pages)
and I have functions, which I may call on 3 out of 20 pages

Soo

What is best practice to do these functions

If I call the function more than once, add it to the header include file, so tis there on all pages

OR

Create a new file for functions, function_includes.php or someting

OR

create a class, and call the functions via the class

OR

if i only call it 2 or 3 times, add it to the file thats calling it, if its more, add it to the header file

OR

err, well I cant think of any other way, so let me know what ya tink


The reason for this is, if I have too many functions on the header, then that is being called on EVERY page, and wont it be a stress for PHP to read "Waste Code" as I wont be usning that function on that page

(As you may have clicked, I am a lil crazy, but thats why ya love me)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.