BNL Home

BNL PHP Templates

Prevent Caching

The following code must be placed ABOVE the <html> tag on the .php page to prevent page caching.

<?php require $_SERVER['DOCUMENT_ROOT'] . "/common/php/scripts/nocache.inc"; ?>

Template Functions, Preset Variables & Debugging

To use the built in debugging tools and to set and subsequently access the preset page variables, you need to include the following code BELOW the <html> tag and ABOVE the <head> tag on the page.

<?php
$debug = False;
require $_SERVER['DOCUMENT_ROOT'] . "/common/php/scripts/functions.inc";
?>

If you set the $debug variable to True, the page will list out all of the preset variables. (See box, below.)

Information About The Current Web Page

$protocol: https
$server: errors.bnl.gov
$serverURL: https://errors.bnl.gov
$siteFileName: /common/templates/documentation/php/bnltemplates/index.php
$queryString:
$siteFileNameQueryString: /common/templates/documentation/php/bnltemplates/index.php
$fullPageURL: https://errors.bnl.gov/common/templates/documentation/php/bnltemplates/index.php
$lastModified: December 2, 2021

Information About The Current User

$logonUser:
$authUser:
$ip: 192.168.1.32
$ipTest:
$userAgent: Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
$referer:

Note that the $debug variable must be set before the functions.inc file is called. We have built a check into the functions.inc file which will override the value of the $debug variable on the production servers to ensure that debug code is only written out on the development servers.

Custom Error Handling

The /common/php/scripts/functions.inc file contains all of the code for custom error handling.

Pages in DEVELOPMENT will display descriptive error messages.  For example:

Error: [1024] Database transaction failed.
File: http://dev.bnl.gov/my-site/somePage.php Line: 74

If you want even more detailed informaiton while in development, then set the $debug variable to True.  You will then see all sorts of ugly error code.

Pages in PRODUCTION will always display friendly error messages without any detailed description of the error.  For example:

Whoops! This page has encountered a problem.
Database transaction failed.
BNL Web Services has been notified.
We apologize for the inconvenience.

The custom error handler function will send an email to WebServices@bnl.gov with detailed information about the error, including URL, line number and a list of all variables that were set at the time the error occurred.