As a PHP beginner, I'm not only struggling with sessions, functions and variables, but also with script design and good coding practices. I'm not sure how to best split up the code between different PHP-files.

At the moment, I'm using a skeleton like this for the main script, the one that the website visitor loads:

<?php

# raw.php

include ("db_functions.php");
include ("html_functions.php");

# define action constants
define ("INITIAL_PAGE", 0);
define ("XX", 1);
define ("YY", 2);
define ("ZZ", 3);


# start

$title = " ";
$header = " ";
html_begin ($title, $header);

# if $action is empty, show the start page

if (empty($action))
$action = INITIAL_PAGE;
if(isset($_REQUEST["action"])) {
$action = $_REQUEST["action"];
}

# which action?

switch ($action)
{
case INITIAL_PAGE:
break;

case XX:
break;

case YY:
break;

case ZZ:
break;

default:
die("Unknown action: $action");
}


html_end();
?>


For each case I call functions stored in different include-files. This way I get a rather clean view of the main script, which makes it easy for me to track what happens when.

Is this a good way to do things?

When is it a good thing to write multi-purpose scripts like my skeleton above, where one thing is shown on first run and then different things depending on what the user does, and when is it better to put not just functions in other files but also splitting the main script in multiple files?

Best regards,

Anders Thoresson


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to