I started out by making several different 'includes' files, each one containg like functions. For example, a few that I've made are...
dbConnect.php <-- connection to db
userAuth.php <-- user authentication functions
formValidator.php <-- checks form elements
errorHandler.php <-- displays error/general messages and logs them to file
css.php <-- detects user's browser and spits out best size fonts
output.php <-- contains most html (in functions)
Now I make another file I named 'mainfile.inc.php' and included all of the existing 'includes' file in it. Now on any new page that needs to be added to the site, I just include 'mainfile.inc.php' and all the functionalities are available to it. If I need to make another includes file, I make it and just add it to 'mainfile.inc.php' and we good to go.
That is the basics, the way I am using some of the functions together to display the varying pages is what I wanted an opinion(s) about.
Here are the two functions which shoulder most of the burden of displaying pages...
Code: Select all
function pageBody($display, $content, $side_menu)
{
$page =
'<center><table border=1 width=95% cellpadding=0 cellspacing=0 bordercolor=#000000>
<tr>
<td colspan=2><img src=''images/logo3.jpg''></td>
</tr><tr>
<td width=18% valign=top class=medium>' .$side_menu. '</td><td width=82% align=center valign=top class=medium>' .$display. '<p>' .$content. '</td>
</tr>
</table></center>';
return $page;
}
function do_html_header($title, $site_content)
{
?>
<html><head><title><?=$title?></title>
<?php
css_site(); <-- function called to check user's browser
?>
</head>
<body>
<?php
echo $site_content;
}Code: Select all
if(check_admin_user())
{
do_html_header($index, pageBody('', indexBody(), display_main_menu(display_admin_menu())));
do_html_footer();
exit();
}
else
{
do_html_header($index, pageBody('', indexBody(), display_main_menu('')));
do_html_footer();
exit();
}Code: Select all
if(chkDuplicates("links", "name", $name)) <-- user attempting to add to database, checks for duplicate entries
{
do_html_header($error, pageBody($error, genMsg('dup', ''), display_main_menu(display_admin_menu())));
do_html_footer();
exit();
}
else
{
Insert in database
}Code: Select all
if($_REQUEST['category'] == 'passed')
{
IF FIELD IS EMPTY
do_html_header($error, pageBody($error, genMsg('empty', ''), display_main_menu(display_admin_menu())));
CHECK IT'S NOT A DUPLICATE
do_html_header($error, pageBody($error, genMsg('dup', ''), display_main_menu(display_admin_menu())));
IF IT'S OKAY
do_html_header($admin, pageBody($admin, genMsg('link_up', ''), display_main_menu(display_admin_menu())));
}There will be dozens of these basically doing the same thing. If $_REQUEST['link'] == 'passed', or $_REQUEST['photo'] == 'passed', etc they will all be handled in the same way.
Hope this is understandable and welcome all input gladly.