Regarding - Splitting PHP Files into Includes

TofuBoy

New Member
Messages
9
Reaction score
0
Points
0
Can someone give me a list of files to split into? I want to keep the files compact by using includes. I don't know if header.php and footer.php would be good files to split.

header.php - Contains tags between <html> and </head>

footer.php - Contains the copyright and from </body> to </html>

-------

And the navbar:
navbar.php - Contains the navbar HREFs
 
Last edited:

Parsa44

New Member
Messages
232
Reaction score
0
Points
0
I cant get include() or require() to work on x10hosting at the moment.
If anybody could help me...
 

wjh2303

New Member
Messages
139
Reaction score
0
Points
0
@ tofuboy
Having a header and footer include files seems to work fairly well for me, and it was recomended to me by someone else on this forum, so its likely an accepted if not recomeded way to do things

@parsa
works fine for me, post a sample of the code you're using, maybe you have a simple syntax error or the like
 

kbjradmin

New Member
Messages
512
Reaction score
2
Points
0
@TofuBoy
i generally use one config file and use it to set variables for my separate parts, like this:

html page
HTML:
<?php
include('config.php');
?>
<!DOCTYPE blah...>
<head>
<?php echo $headCode; ?>
</head>
config.php
PHP:
<?php
$headCode = '<title>This is where your code goes.</title>';

etc...
?>
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
250
Points
63
I've read somewhere that it is the best coding practice to keep any function 50 lines or less (excluding comments and long strings). So, it would be best to use many small functions instead of one huge function. This just makes your code easier to understand to you and for anyone who may need to look at it in the future.

It is also good to group functions that are often used together into the same file, so they are all included at once. Headers and Footers are used on every page, every time, so really, you could put them in the same file and save yourself a few keystrokes and probably a few processor cycles here and there. It doesn't make a lot of sense to put
Code:
include('header.php');
include('footer.php');
In every file when you could just say
Code:
include('whatever.php');

An exception would be if your code does not have a function. If your header is always the exact same thing, you don't need a function. Just put the code in the file then call header.php when you want the header output. Here, it makes more sense to separate them, since there's something in between the header and footer, presumably :p
 

Livewire

Abuse Compliance Officer
Staff member
Messages
18,169
Reaction score
216
Points
63
For me, I split configuration, frequently used functions, and my mysql connect's into them.


The mysql-connection's a big one though - include("logmein_admin.php") or include("logmein.php"), depending if it needs all permissions, or just select.

The reason it's a big one? Locally, the password and username are different. So x10's got a different logmein and logmein_admin than localhost.

I don't have to change my code to make it work on x10 :)


If anything, I'd store mysql username/passwords in an include, then bury it in a folder with a .htaccess "Deny From All" setting. Seems include and require CAN access folders that have been set to "deny from all," which makes it handy - index.php can include includes/logmein_admin.php, but there's no way to actually access logmein_admin.php directly ^_^
 

freecrm

New Member
Messages
629
Reaction score
0
Points
0
I always use includes for headers and footers and yes, it is an accepted way of doing things.

I think your have to have an intermediate account for includes to work though which is why you might be having problems.
 
Top