Hmm, just randomly thought I'd attempt to make some forum software, and figured that if it's going to be something that other people could be editing etc, it'd be better if it was well structured.
So, for index.php, where everything is brought together, i have the current code (the significant part anyway, reduced slightly for posting purposes):
include_once('sources/header.php'); // DB connect, logo, nav etc etc
include_once('sources/jscript.php'); // Javascript functions
if (isset($_GET['act'])) {
$act = $_GET['act'];
// A switch which will include the appropriate file, based upon
// what the $_GET variable is. Each file is concluded with exit2()
// function as described in code section below.
switch ($act) {
case ($act == 'newtopic' && isset($curforum)):
include('sources/newtopic.php');
break;
case ($act == 'register'):
include('sources/register.php');
break;
case ($act == 'login'):
include('sources/login.php');
break;
case ($act == 'logout'):
include('sources/logout.php');
break;
case ($act == 'usercp'):
include('sources/usercp.php');
break;
case ($act == 'memberlist'):
include('sources/members.php');
break;
case ($act == 'viewprofile'):
include('sources/profile.php');
break;
// etc etc etc...
}
}
// Display the forums if thecode hasn't already exited (i.e. it's on
// the main page)
include('sources/viewforums.php');
// Online users, members etc, again will only display on main
// page as code will have exited otherwise.
include ('sources/footerstats.php');
function exit2()
{
// Footer stuff
exit();
}
So basically, I was wondering if that would be a viable way of doing things. It works, yes, but I'm not sure how it would be performance wise etc...so any comments/suggestions/alternatives etc?
Thanks 🙂