unreal128 wrote:I am not speaking so much of the script I wrote but rather the best practices for verifying if a function failed or passed later on. (...)
require(blah.inc.php); // contains authCookie();
unset($user);
authCookie();
if (isset($user)) {
// write HTML for authorized users
} else {
// write HTML for un-authorized users
}
One simple way would be store the result in a variable.
require(blah.inc.php); // contains authCookie();
unset($user);
authCookie();
$userOK = isset($user);
if ($userOK) {
// write HTML for authorized users
} else {
// write HTML for un-authorized users
}
You can now use $userOK anywhere you like in the page. It's more efficient than repeatedly calling the same function.
As I'm sure you've heard by now, you can include database calls at the start, middle or end of your scripts. There's no trick, no magic, no special code to show. if you have a tag-enclosed PHP snippet in your HTML, you can move it anywhere within that html.
Like the others here, the only possible confusion I can think of is the "header" function which becomes redundant if you attempt to call it after you have begun sending html content, as it has to preceed it. If you really, really need to, you can get around this using content buffering, but if that's your only reason for content buffering, you should revisit your design.