This seems like a rambling post, but it will be easy to follow. I was wanting to get some feedback on the way I am coding a site from scratch. I am attempting to put together a general site framework that I can use over and over.
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...
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;
}
You can see that pageBody() is passed as an argument to do_html_header() and that it itself accepts 3 arguments. I think that this is okay, but the way I am having to constantly call the function is what I'm not real sure about. An example of how they are called on the index page is below. You can see that if(check_admin_user()) is true, display_admin_menu() is passed to display_main_menu(), otherwise not.
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();
}
Another example below, suppose there is an error, this is what might be called...
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
}
For the most part, I have one master file that just sits and waits for instructions passed via hidden form fields. It has many 'if' statements looking for what is passed to it...
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.